Hey guys, i’m using c# in unity and basically there’s a timer
The timer starts at 0, and when it is == to 0 the player can attack. When the player does attack the timer gets == to the cooldown which is 2 seconds.
The update function then decrements it back to 0 enabling the player to attack again.
//put timer on attack
public float attackTimer;
public float coolDownCountTimer ;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDownCountTimer = 2.0f;
}
// Update is called once per frame
void Update () {
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
{
attackTimer =0;
}
if(attackTimer>0)
{
attackTimer = 0;}
Debug.Log(attackTimer);
//when player clicks we attack, we look for mouse input
if(Input.GetMouseButtonDown(0))
{
if(attackTimer == 0)
{
//Debug.Log ("Attack");
Attack(pDamage);
//eveyr time we attack, reset attack timer to cool down
attackTimer = coolDownCountTimer;
}
}