Change GUI.Label text while it's active?

Hello, I’m making a code that when I press login it should wait for 5 seconds. The code uses a GUI.Label to show the current time remaining, but if the variable change, the text stays as it is. The if statement is inside the OnGUI functon.

Code:

if (connecting)
{
connectTime = 5;
GUI.Label (Rect (10,60,130,90), "Loggar in om: " + connectTime);
}
yield WaitForSeconds(1);
connecttime = 4;

This shows the text: “Loggar in om: 5” but stays like that even after the variable changes.

You can’t call yield from within OnGUI. You should use StartCoroutine and update connectTime there. Example code (untested):

...
function OnGUI() {
    if (connecting)
    {
        GUI.Label (Rect (10,60,130,90), "Loggar in om: " + connectTime);
    }
}
...
// add StartCoroutine(StartConnecting(5)) where you set connecting to true now
function StartConnecting(time: int) {
    connecting = true;
    connectTime = time;
    while (connectTime > 0) {
        yield WaitForSeconds(1.0);
        connectTime -= 1;
    }
    connecting = false;
}