Bring Up Another GUI Box With Buttons When A Button Is Clicked?

Hey Guys

Im working on a small horror game at the moment based off the anime, Hetalia and im having trouble with the main menu. See it has 3 buttons. One to start the game. One to exit and one thats a level select. When i click the level select i want it to bring up a new GUI box next to the main menu gui and display the levels. But so far. It doesnt draw the box when i click the level select or bring up the new buttons!

Here IS My Code

#pragma strict

function Start () {

}

function Update () {

}

// JavaScript
function OnGUI () {
	// Make a background box
	GUI.Box (Rect (350,100,200,100), "Canada's Nightmare");
	GUI.Box (Rect (150,100,200,100), "Choose Your Nightmare");
	// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
	if (GUI.Button (Rect (350,120,200,20), "Enter The Nightmare")) {
		Application.LoadLevel (1);
	}
    if (GUI.Button (Rect (350,150,200,20), "Choose The Nightmare")) { // Level Select begins
	    
	       if (GUI.Button (Rect (150,130,200,90), "Britains Coal Mines")) {
	       Application.LoadLevel (1);
	       } 
	       
	       if (GUI.Button (Rect (150,160,200,90), "No Level Here")){
	       
	       }
	} // Level Select Ends
	
	if (GUI.Button (Rect (350,180,200,20), "Wake Up...")) {
		Application.Quit();
	}
}

Thanks in advance!

The problem you’re facing is simple: pressing a GUI.Button in unity only calls the function within the brackets >ONCE< meaning, it’s showing for a single frame and disappears. However there’s a common workaround for that, just assign a new variable which is set to TRUE whenever someone clicks on the button and as long as it’s true the button are shown, otherwise not

for example

 var ShowOtherGUIElements : bool; //true = show the other GUI elements

and then in your OnGUI()

if(ShowOtherGUIElements)
{
//your new buttons/GUI elements here
}

I hope that helped you out :wink: