I am in the process of making a game where the player uses a spell from a wand, however I want there to be a cooldown in between shots. The problem is that cool down works for the first shot, but after that the player can spam fire and shoot all they want. I cannot seem to fix the problem. Script is included below.
var ShootSpeed : float = 10;
var projectile : Rigidbody;
var shoot : float = 1;
var wand : GameObject;
var canShoot : boolean = true;
function Update () {
if(Input.GetButtonDown("Fire1") && canShoot == true){
Charge();
canShoot = false;
}
if(canShoot == false){
CoolDown();
}
}
function Shoot(){
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3.forward * ShootSpeed);
clone.transform.parent = null;
}
function Charge(){
wand.animation.Play("WandCast");
yield WaitForSeconds(.5835);
Shoot();
}
function CoolDown(){
yield WaitForSeconds(4.5);
canShoot = true;
Debug.Log("Done!");
}