- Home /
Checkpoint GUI enabled then disabled trouble
Hey, I have been trying to create a checkpoint GUI box that pops up for about 3 seconds to say the player hit a checkpoint, and then disappear. i have been messing around with this for days and looking at other people's ideas for turning GUIs off, to no avail. i already have the checkpoint GUI pop up when i run into a collider, Im now only having trouble turning it off. this was my last failed attempt, mostly due (i believe) to the yield object not working in the GUI function:
function OnGUI() { if(check) { GUI.Box(Rect(Screen.width - 100,0,100,50), "Check Point"); timer = 1; }
if(timer == 1)
{
yield WaitForSeconds(3);
check = false;
timer = 0;
}
}
obviously, using javascript. any help would be greatly appreciated
Answer by DaveA · Mar 22, 2011 at 12:26 AM
var delay = 3.0; private var checkTime = 0.0; private var check = false;
function TurnOnCheck() { checkTime = Time.time; check = true; }
function OnGUI() { if (check) GUI.Box(Rect(Screen.width - 100,0,100,50), "Check Point"); if ((Time.time - checkTime) >= delay) check = false; }
Call TurnOnCheck() somewhere, like when your checkpoint is reached.
Answer by tool55 · Mar 22, 2011 at 12:34 AM
Perhaps you need to amend your if statement:
if (check && !timer)
Answer by Eric5h5 · Mar 22, 2011 at 12:48 AM
It's much simpler and more efficient if you enable and disable the script as appropriate. You should make the script disabled in the inspector by default, so it's only enabled when you call the ShowGUI function with the time you want it to be displayed.
function OnGUI() { GUI.Box(Rect(Screen.width - 100,0,100,50), "Check Point"); }
function ShowGUI (timer : float) { enabled = true; yield WaitForSeconds (timer); enabled = false; }
Your answer
Follow this Question
Related Questions
About "How do I make laps in a racing game?" 2 Answers
Change Font Style OnMouseEnter 0 Answers
GUIDrawTexture Based Crosshairs 0 Answers
When I pause my game and enable canvas and then resume my keyboard starts controlling the menu... 1 Answer
How to know if something is selected in Hierarchy or in project. 5 Answers