unity shoot with cooldown code example
Example: unity everytime character shoot he has a short cooldown
#pragma strict
//The interval you want your player to be able to fire.
var FireRate : float = 1.0;
//The actual time the player will be able to fire.
private var NextFire : float;
function Update () {
//If the player is pressing fire AND The current time is > than when I want them to fire
if(Input.GetButton("Fire1") && Time.time > NextFire)
{
//If the player fired, reset the NextFire time to a new point in the future.
NextFire = Time.time + FireRate;
//Weapon firing logic goes here.
Debug.Log("Firing once every 1s");
}
}