- Home /
If using a conditional-situational menu, such as a pop-up, must wait till next OnGUI?
If you are using a conditional-situational menu... such as a pop-up dialog ("Are you sure you want to quit", etc) that occurs after you click on another gui button ("Quit"), is the only way to create both the toggle-button gui menu and check the conditional to wait until the next OnGUI
-call?
In this case, every time you have a dialog like this, you would have to use a global to check for loading the dialog on next onGUI?
Answer by cjmarsh · Jan 05, 2011 at 12:43 PM
After clicking the GUI Button "Quit" you could instantiate an empty game object prefab with an attached OnGUI script for the pop-up confirmation. This way you could simply instantiate and destroy the situational code without having it embedded in the overall global call.
Answer by PrimeDerektive · Jan 05, 2011 at 01:24 PM
You could just use boolean vars to toggle what GUI code you want to show, like this:
private var showQuit : boolean = false;
function OnGUI(){
if (GUI.Button (Rect (10,10, 100, 50), "Quit Game")) {
showQuit = true;
}
if (showQuit == true){
GUI.Button(Rect ((Screen.width/2), (Screen.height/2), 100, 50), "Are you sure you want to quit?");
}
}
so... my question is if this is the only way to do such conditional menu's and doesn't it add unnecessary processing since it's checked each frame?
Every gui element is checked every frame, so adding a bool check is no more cpu intensive than simply adding another gui element... the difference is negligible, if there is one at all. This is the only way I've ever seen it done, unless you want to be instantiating/destroying objects all over the place with different GUI code on them, which is probably intensive even moreso.