I have a number of problems with this script. If anyone can help on anyone of them, it would be greatly appreciated.
- The script wont halt the shooting, which is what the wait() function is for.
- The script shoots at random every which way, I don’t know why
- The script creates tons of the object when held down
The script:
var projectile : Rigidbody;
var speed = 20;
var fire : boolean = false;
var pressed = 0;
function Update () {
if(Input.GetKey(KeyCode.F) && (pressed == 1)) {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 3);
Debug.Log("Reloading");
wait();
Debug.Log("Ready to Fire!");
pressed = 0;
}
if(Input.GetKey(KeyCode.F)) {
pressed = 1;
Debug.Log("Pressed E");
}
}
function wait() {
yield WaitForSeconds (5);
}