- Home /
Gun script not working in 5.6
I have just upgraded to 5.6 and a script that had been working just fine in 5.4 has just stopped working. It works for about 5 seconds when I launch the game then stops with no compiler errors.
Script for the gun:
public GameObject bullet;
public GameObject bulletHole;
public float delayTime = 0.5f;
private float counter = 0;
void FixedUpdate ()
{
if(Input.GetKey(KeyCode.Mouse0) && counter > delayTime)
{
Instantiate(bullet, transform.position, transform.rotation);
GetComponent<AudioSource>().Play();
counter = 0;
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
if(Physics.Raycast(ray, out hit, 100f))
{
Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
}
}
counter += Time.deltaTime;
}
And the one for the bullet once fired from the gun:
public float speed = 1f;
void Start ()
{
Destroy(gameObject, 5f); //Delete the bullet after 5 seconds
}
void Update ()
{
transform.Translate(0, 0, speed);
}
Comment