HELP! I’m using unity 4.6.9, and I have a script to make a gun shoot. It works perfectly, except you can fire as fast as you want, as in several bullets per second. I want to have like a one second delay between the shots that you can fire. However, after trying again and again to get a yield waitforseconds (5); to work, I haven’t been able too. The script below does nothing. Or rather, it does exactly as it does normally, with absolutely no delay. I’ve even tried ramping the delay up to 100, and it still doesn’t do anything. I’ve been trying for days!!!
var projectile : Rigidbody;
var speed = 10;
function wait() {
yield WaitForSeconds(1);
}
function Update () {
if(Input.GetMouseButtonDown(0)) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3 (0, 0, speed));
audio.Play();
Destroy (clone.gameObject, 5);
}
wait();
}
Please help!!!