Show menu upon button click

Hello there

Just couple of days with unity3d. I have menu system jumping from one scene to another. While playing game I have quit button on the top hand right side of the screen. Upon clicking the “quit” button, I would like to display a menu which has the following options “Back to game” “how to play” “restart?” .

For now I am just looking a way to display the menu.

Thanks

Lots of different ways, of course. But the basics are the same:

  1. Build the menu with those buttons.
    This will be done using the GUI functions which it sounds like you know how to use since you have a quit button already. You could make this its own script component or part of your general HUD/GUI component or what have you.

  2. Toggling it on and off.
    This can be done either via SendMessage() or a variable. I like the SendMessage myself but either works fine, depending on how you’re using your code.

For example, you could have a variable that the main gui and the menu component can read. When clicking the button you would set the variable (say ‘ShowEscapeMenu’) to true. Your escape menu’s OnGUI would basically then look like this:

void OnGUI()
{
   if(ShowEscapeMenu)
   { ... }
}

.

Or you could have the exit button fire off a SendMessage(‘ShowEscapeWindow’) and in your escape menu component:

void ShowEscapeWindow()
{
   ShowMenu = true;
}

(with the same OnGUI approach as above)

Again, lots more ways, but hopefully this will get you started!

Thanks Timmer for your reply,

This is my code and I did do something like already.

function inGameMenu() {
	
	showGameMenu = false;
	
	if(!showGameMenu) {
		GUI.Box (Rect (300,80,200,180), "Greenophilia");
	//If Level 1 button is clicked , 1st level is loaded 
	if (GUI.Button (Rect (320,110,150,20), "Back to game")) {
		
		Application.LoadLevel ("level2");
	}

	// Make the second button to load second level
	if (GUI.Button (Rect (320,150,150,20), "How to Play")) {
		Application.LoadLevel ("Tutorial");
	}
	
	if (GUI.Button (Rect(320,190,150,20), "Restart")) {
		Application.LoadLevel ("quit");
	}
	
	print ("Printing in game menu");
	}

}

function OnGUI () {
	
		if (GUI.Button (Rect (10,10,200,20), "Meet the flashing button")) {
			//GUI.Box (Rect (0,0,100,50), "Top-left");
			inGameMenu();
						
			// Make a background box
		}
}

It displays the print message, but not the UI.

Any thoughts on this?

Thanks

Got it working …

var inGameMenuActive:boolean = false;

function OnGUI () {

	if (GUI.Button (Rect (525,7,50,20), "Quit")) {
		inGameMenuActive=!inGameMenuActive;
		//Application.LoadLevel ("inGameMenu");
	
	}
	
	if(inGameMenuActive) {
     // GUI.Label(Rect(140,10,200,200),"Hello World");
     
     // Make a background box
	GUI.Box (Rect (300,80,200,180), "Greenophilia");
	//If Level 1 button is clicked , 1st level is loaded 
	if (GUI.Button (Rect (320,110,150,20), "Back to game")) {
		
		Application.LoadLevel ("level2");
	}

	// Make the second button to load second level
	if (GUI.Button (Rect (320,150,150,20), "How to Play")) {
		Application.LoadLevel ("Tutorial");
	}
	
	if (GUI.Button (Rect(320,190,150,20), "Restart")) {
		Application.LoadLevel ("quit");
	}
}
}