Adding some GUI to an main menu

Hello there. So i am trying to add instructions to my mainmenu when you press a button.
But its not really working with my old mainmenu script.

using UnityEngine;
using System.Collections;

public class MenuObject : MonoBehaviour 
{
    
    public bool showGUI = false;
    public bool isQuit = false;
    public bool isInstructions = false;

	void OnMouseEnter()
	{
		renderer.material.color = Color.black;
	}
	
    void OnMouseExit()
	{
	
	renderer.material.color = Color.white;	
	
	}

    void OnMouseDown()
    {
	if(isInstructions)
		
	
    {
		
	showGUI = true;	
		
	}
	else
	{
	    if(isQuit)
	{
		Application.Quit();
		
	}
	else
	{
		Application.LoadLevel(1);
		
	}
}

}

void OnGUI () {
if(showGUI)
GUI.Box (new Rect( 0, 0, 10000, 10000), "");
GUI.Label (new Rect( 400, 200, 150, 30), "Instructions");
if(GUI.Button (new Rect( 400, 300, 150, 30), "Back" )) {
showGUI = false;		
}
}
}

So that is what ive tried.
In the box i am gonna write some instructions on how to play the game etc.
But when i run the mainmenu. The button and the text is already there.
It doenst toggle? Only the GUI.Box toggles?

  • Frederik

You forgot some brackets, thats all :wink: (your if (showGUI) statement)

using UnityEngine;
using System.Collections;

public class MenuObject : MonoBehaviour 
{

    public bool showGUI = false;
    public bool isQuit = false;
    public bool isInstructions = false;

    void OnMouseEnter()
    {
       renderer.material.color = Color.black;
    }

    void OnMouseExit()
    {

    renderer.material.color = Color.white; 

    }

    void OnMouseDown()
    {
  		if(isInstructions)
		{
			showGUI = true;    
		} else {
        	if(isQuit)
    		{
       			Application.Quit();
			} else {
       			Application.LoadLevel(1);
    		}
		}
	}

	void OnGUI () {
		if(showGUI) {
			GUI.Box (new Rect( 0, 0, 10000, 10000), "");
			GUI.Label (new Rect( 400, 200, 150, 30), "Instructions");
			if(GUI.Button (new Rect( 400, 300, 150, 30), "Back" )) {
				showGUI = false;       
			}
		}
	}
}