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);
}
}
}