Count Down Timer Problem...

The following code will indeed work properly but only when I use GUI.Button to start the timer. If I use that condition with the “gm.myValues” dictionary (which are values changed in game by the user similar to pressing a button) it wont work…which boggles my mind…

private bool start = false;
private float startTime;
private float displaySeconds;

private void OnGUI() 
{
    //if (Mathf.Approximately(gm.myValues["x"], 1.0F)  Mathf.Approximately(gm.myValues["y"], 0.0F))
    if (GUI.Button(new Rect(100,200,100,100), "Start (or restart) Timer..."))
    {
        startTime = Time.time;
        start = true;
    }
		
    if (start)
    {
        float guiTime = Time.time - startTime;
		
        displaySeconds = 30 - (guiTime % 60); //start counting down at 30
        displaySeconds = Mathf.CeilToInt(displaySeconds); //dont display milli's
			
        GUI.Label(new Rect(Screen.width/2-135, 65, 300, 200), displaySeconds.ToString(), s);
    }
}

So what happens above with the code as is? When the a button is pressed a timer counts down from 30.

What is my problem?

If I use the condition with the gm.myValues needing to be true for certain values, the GUI.Label will print my the time as a string but it will not count down!

Naturally, when the condition is true, it doesn’t count down.

I am all analyzed out and need a break, so I thought I’d post… :x

Same issue as another guy, though it wasnt called countdown timer.

http://forum.unity3d.com/threads/92401-yield-WaitForSeconds-Not-Working

It is bascially a Coroutine that yeilds during the countdown. Once finished you can set a variable to start play, or set the timeScale or whatever you need.