How to check a if statement every (...) seconds

How do you repeatedly check an if statement every second.
i am making a fps and am trying to make it so when you run out of ammo (currentClip = = 0) then i want “theDamage” to be set to zero. It works the only problem is that when i run out of ammo, once, then i reload and “theDamage” stays on zero but my “currentClip” goes back to 75. I want to make it so it checks the function every second to see if the (currentAmmo) is equal to zero. Thx in advance :slight_smile:

Her is my code…

function Update ()
{
if (currentClip == 0)
{
theDamage = 0;
}

var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay (Vector3(Screen.width0.5, Screen.height0.5,0));

	if (Input.GetButton("Fire1") && currentClip >= 1 && !reloading)
	{
		if (Physics.Raycast (ray, hit, 20000))
		{
		hit.transform.SendMessage("ApplyDamage", theDamage, SendMessageOptions.DontRequireReceiver);

		}
	}

}

As suggested, use a Coroutine.

void Start() {
     StartCoroutine("MyCoroutine");
}

private IEnumerator MyCoroutine() {
     while(true) {
          if (currentClip == 0) { 
               theDamage = 0;
          }
          yield return WaitForSeconds(1);
     }
}

Hi !

without coroutine you can do like that

float time, waitingTime = 1;

if (Input.GetButton("Fire1") && !reloading)
{
     if (time  < Time.time)
     {
            time = Time.time + waitingTime;
            //do action
     }
     else Debug.Log("wait");
}