I'd use a coroutine for this. Have a property (boolean) to indicate if times up or not. Every time you want to start the 3 second timer, call the public method "StartTimer" - It will safely stop and start a new timer. In your Update method, monitor the timesUp property ... If it goes true, time is up!
public bool timesUp = false;
public void StartTimer()
{
StopCoroutine(StopWatchCR());
StartCoroutine(StopWatchCR());
}
private IEnumerator StopWatchCR()
{
timesUp = false;
yield return new WaitForSeconds(3);
timesUp = true;
}
↧