Somehow I got into the habit of controlling GUI menus by setting a variable that the OnGUI function tests for to draw the GUI, instead of enabling or disabling the entire script.
Like:
// toggle this from another script
public var onGUIStuff : boolean = false;
function OnGUI ()
{
if (doGUIStuff)
{
// draw GUI calls here
// now close the window
if (Button ("Close") {
// close this menu
doGUIStuff = !doGUIStuff;
}
}
}
But I realized that this means that all the OnGUI scripts are merrily churning away doing that test. (By “all” I mean less than 10 right now.)
Is that a bad habit and something I should avoid? Or no big deal? Is it smarter to toggle .enabled for those scripts? Is it cool for an object to disable itself (as in when the close button is clicked)?
The GUI scripts in question are just children of an option menu, so are not actively monitoring the game state in order to be triggered (except for the hot key for opening the main menu, so that has to be constantly active.
Thanks,
Steve