Getting a timer to go to 0

Hey everyone,

What i’m trying to do is after the timer goes to 0 i’d like for the timer to stop for 2 seconds and then reset and thus the process will repeat. What i have so far is…

	public GUIText timerText;
	public float timer = 0.0f;
	public float timerMax;

	void Start()
	{
		timer = timerMax ;
	}

	void Update()
	{
		if (timer <= 0.0f)
		{
			StartCoroutine(wait(2.0f));
			timer = timerMax;
		}

		else
		{
			countdown();
		}
	}

	void countdown()
	{
		timer -= Time.deltaTime;
		updateTimerText();
	}

	IEnumerator wait(float waitTimer)
	{
		yield return new WaitForSeconds(waitTimer);
	}

	void updateTimerText()
	{
		timerText.text = "Timer: 

" + Mathf.Round(timer * 10f) / 10f;
}

This is also used with a GUIText to print out the timer but that shouldn’t really matter. The issue at the moment is that it’s not stopping for the 2 seconds. I think this might be due to it not reaching 0 but then again the timer does reset so i’m not too certain.

Any help will be appreciated!

If anyone is interested, just as @hexagonius said i just had to use a while loop :slight_smile: