- Home /
Draw / don't draw buttons based on boolean variable
I have a feeling I'm missing something really simple, but I can't get this to work. I'm just having a menu item (quit) change to "sure?" after a click.
With the debug log in there it shows quitToggle is staying true, regardless of multiple clicks (it should at least change to false after 1 click, right?). But if I move the debug log to the other side of the variable change, it prints 'false' every click instead. I'm guessing its something to do with the variable not sticking around by the time the GUI updates next frame? Anyway, I'm stumped. Help appreciated, thanks!
I have my "public bool quitToggle = true;" after monobehavior but before void onGUI. I did try swapping it around in various places, but no luck. Sorry, I'm kinda new :D
// Quit Game Button (ask if you're sure)
if (quitToggle = true) {
if (GUI.Button (new Rect (menuPosX+5,menuPosY+110, buttonSizeX, buttonSizeY), "Quit", darkStyle)) {
Debug.Log(quitToggle);
quitToggle = false;
}
}
// Yes I'm sure button
if (quitToggle = false) {
if (GUI.Button (new Rect (menuPosX+5,menuPosY+110, buttonSizeX, buttonSizeY), "Sure?", darkStyle)) {
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
}
Why are you using System.Diagnostics.Process.GetCurrentProcess().$$anonymous$$ill(); to kill the game?
Application.Quit(); is designed to do it
Application.Quit was crashing. Looked into it and the best answer I found was "its a problem with unity, wait for an update". So I used that as a workaround. Any advice?
Answer by Graham-Dunnett · Apr 04, 2013 at 11:18 AM
Read up on the assignment operator =
and the equality operator ==
. Inside an if statement you almost always need the equality operator.
Thanks much! Learning too many languages at the same time messin' with me.
Your answer

Follow this Question
Related Questions
Creating a pause menu (problem using Time.timeScale) 3 Answers
how made GUIButton for car game 2 Answers
GUI buttons 2 Answers
GUI.button and onClick Terrain 2 Answers
LoadLevel at the end of a sound ! (pb with Coroutine) 0 Answers