GUI Menu

Goodmorning everyone.
I am creating a main menu (2d), with gui elements, and i have a question:
when user click on a menu button, how to switch to the next gui.
examplei have :

play
options
exit.

user clicks on options and the gui elements change to:

volume
difficult,

Is this possible?

yes this is possible, you can have multiple gui scripts (or just one with multiple complete gui’s in it) and activate one or the other based on what buttons are pressed.

Just make sure the gui only gets drawn when that gui is active

thanks, can you please help me with script?

what gui do you use?

if you have no experience i advice you to check out some basic tutorials on how unity gui works
http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html

thanks.
i am using the normal gui,

.
every think are gui buttons and labels.

do you know how to hide and show gui elements?

use guitexture,enable = false.

or where you normally do this:

void OnGUI() {
  if (GUI.Button(Rect(0,0,10,10),"Some"))
    dosomething();
}

now do this:

var thisGUIActive : bool;

void OnGUI() {
  if (thisGUIActive) {
    if (GUI.Button(Rect(0,0,10,10),"Some"))
      dosomething();
  }
}

then toggle the thisGUIActive variable based on whether the current gui should display or not

oke, thanks everyone!

You can also put your GUI into booleans or cases:

var isStarting = true;
var isOptions = false;

function OnGUI () {
	if (isStarting) {
		if (GUI.Button (Rect (10, 10, 100, 20), "Options")) {
			isStarting = false;
			isOptions = true;
		}
		if (GUI.Button (Rect (10, 40, 100, 30), "Play")) {
			Application.LoadLevel (1);
		}
	}
	
	if (isOptions) {
		if (GUI.Button (Rect (10, 10, 100, 20), "Volume")) {
			Debug.Log ("Volume Button");
		}
		if (GUI.Button (Rect (10, 40, 100, 20), "Sensitivity")) {
			Debug.Log ("Sensitivity Button");
		}
		if (GUI.Button (Rect (10, 70, 100, 20), "Done")) {
			isStarting = true;
			isOptions = false;
		}
	}
}

Or you can use an enum and a switch, which is more efficient:

enum UIState {Starting, Options}

var uIState : UIState;

function Start () {
	uIState = UIState.Starting;
}

function OnGUI () {
	switch (uIState) {
		case UIState.Starting:
			if (GUI.Button (Rect (10, 10, 100, 20), "Options")) {
				uIState = UIState.Options;
			}
			if (GUI.Button (Rect (10, 40, 100, 20), "Play")) {
				Application.LoadLevel (1);
			}
		break;
		
		case UIState.Options:
			if (GUI.Button (Rect (10, 10, 100, 20), "Volume")) {
				Debug.Log ("Volume Button");
			}
			if (GUI.Button (Rect (10, 40, 100, 20), "Sensitivity")) {
				Debug.Log ("Sensitivity Button");
			}
			if (GUI.Button (Rect (10, 70, 100, 20), "Done")) {
				uIState = UIState.Starting;
			}
		break;
	}
}

This way you can keep it all in one script.

Further: GUI code doesn’t need to reside inside OnGUI as long as it’s called from OnGUI, so you can organize your code in a more disassociated fashion for easy maintenance:

enum UIState {Starting, Options}

var uIState : UIState;

function Start () {
	uIState = UIState.Starting;
}

function OnGUI () {
	switch (uIState) {
		case UIState.Starting:
			GUIStarting ();
		break;
		
		case UIState.Options:
			GUIOptions ();
		break;
	}
}

function GUIStarting () {
	if (GUI.Button (Rect (10, 10, 100, 20), "Options")) {
		uIState = UIState.Options;
	}
	if (GUI.Button (Rect (10, 40, 100, 20), "Play")) {
		Application.LoadLevel (1);
	}
}

function GUIOptions () {
	if (GUI.Button (Rect (10, 10, 100, 20), "Volume")) {
		Debug.Log ("Volume Button");
	}
	if (GUI.Button (Rect (10, 40, 100, 20), "Sensitivity")) {
		Debug.Log ("Sensitivity Button");
	}
	if (GUI.Button (Rect (10, 70, 100, 20), "Done")) {
		uIState = UIState.Starting;
	}
}