- Home /
Question by
valrossen_Oliver · Apr 07, 2014 at 12:13 PM ·
javascriptguivariabletimelabel
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.
Comment
Best Answer
Answer by povilas · Apr 07, 2014 at 05:07 PM
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;
}
Your answer
Follow this Question
Related Questions
Need help with GUI label not displaying variable 1 Answer
GUILabel doesn't show up 1 Answer
Optimizing OnGUI 1 Answer
Limiting digits in GUI displayed variables (or "snap to" GUI slider). 1 Answer
Setting Scroll View Width GUILayout 1 Answer