GUI.Label Not Disappearing

Here’s my code:

var toggleBox = false;
var toggleLabel = false;
var customSkin : GUISkin;
function OnGUI(){
GUI.skin = customSkin;
		// Make a background box
		GUI.Box(new Rect(10,10,1260,100), "Planet Domination");

		// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
		if(GUI.Button(new Rect(20,40,100,30), "Singleplayer")) {
			Application.LoadLevel(1);
			Destroy(this);
		}
		if(GUI.Button(new Rect(150,40,100,30), "Multiplayer")) {
			Application.LoadLevel(1);
			Destroy(this);
		}
		if(GUI.Button(new Rect(280,40,100,30), "Options")) {
			Application.LoadLevel(1);
			Destroy(this);
		}
		if(GUI.Button(new Rect(410,40,100,30), "About")) {
         toggleBox = true;
         toggleLabel = true;
		}
 
		if (toggleBox == true)
		if (toggleLabel == true)

		GUI.Box(new Rect(10,150,500,200), "About the Game");
		GUI.Label(new Rect(20,170,475,490), "Created in 2014 by Pixel-Made Studios");
}

When I put this code in, the GUI.Label won’t disappear when the scene starts. Can anyone help me?

Your problem is the if-statements without braces:

if (toggleBox == true)
if (toggleLabel == true)

GUI.Box(new Rect(10,150,500,200), "About the Game");
GUI.Label(new Rect(20,170,475,490), "Created in 2014 by Pixel-Made Studios");

This actually means:

if (toggleBox == true) {
    if (toggleLabel == true) {
        GUI.Box(new Rect(10,150,500,200), "About the Game");
    }
}
GUI.Label(new Rect(20,170,475,490), "Created in 2014 by Pixel-Made Studios");

This is because a braceless if-statement only runs to the next statement: the first one runs to the second one, and then the second one runs to the GUI.Box() statement. The GUI.Label() statement is completely outside of the if block. You have to use braces to do what you want here, so it’d be:

if (toggleBox == true) {
    GUI.Box(new Rect(10,150,500,200), "About the Game");
    if (toggleLabel == true) {
        GUI.Label(new Rect(20,170,475,490), "Created in 2014 by Pixel-Made Studios");
    }
}

I tend to always use braces with if-statements, and it saves me any confusion about where the if block ends. If you want to use braceless if-statements wherever you can, though, the if (toggleLabel) doesn’t need braces.