- Home /
Question by
Starflight1 · Nov 16, 2020 at 02:21 PM ·
script.game
How to shoot a raycast into the skybox?
I'm a making a 3d space shooter game. I shoot a raycast for my projectile but since the skybox doesn't have a collider I can't shoot into it which makes the game a bit boring. Is there a way to shoot raycast into the skybox. Here is my code:
public float shootRate;
private float shootRateTimeStamp;
public GameObject bullet;
RaycastHit hit;
float range = 1000f;
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (Time.time > shootRateTimeStamp)
{
shootRay();
shootRateTimeStamp = Time.time + shootRate;
}
}
}
void shootRay()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, range))
{
GameObject laser = GameObject.Instantiate(bullet, transform.position, transform.rotation) as GameObject;
//Ignore this , it just makes the bullet move and explode
laser.GetComponent<ShotBehavior>().setTarget(hit.point);
GameObject.Destroy(laser, 2f);
}
}
}
Comment
Answer by myzzie · Nov 16, 2020 at 02:55 PM
else
{
laser.GetComponent<ShotBehavior>().setTarget(ray.direction * maxLength);
}
Your answer
Follow this Question
Related Questions
Score no longer works after backing up my game 0 Answers
problem with create game Android 2 Answers
Ban Players from my game 2 Answers
Pong goal collision 3 Answers