Main Menu Problem?

Hello Unity Answers,

I have created a main menu, and the problem I’m having is when I click either Instructions or Exit text/button both pop up boxes appear instead of If I clicked Instructions, then the UI image on the left appears and if I click Exit the UI image on the right appears. .

All ideas, help, suggestions welcome.

alt text

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class menuScript : MonoBehaviour {

	public Canvas quitMenu;
	public Canvas instructionMenu;
	public Button startText;
	public Button instructionText;
	public Button exitText;



	// Use this for initialization
	void Start () 
	{
		quitMenu = quitMenu.GetComponent<Canvas> ();
		instructionMenu = instructionMenu.GetComponent<Canvas> ();
		instructionText = instructionText.GetComponent<Button>();
		startText = startText.GetComponent<Button> ();
		exitText = exitText.GetComponent<Button> ();
		quitMenu.enabled = false;
		instructionMenu.enabled = false;
	}

	public void ExitPress()
	{
		quitMenu.enabled = true;
		instructionMenu.enabled = true;
		startText.enabled = false;
		instructionText.enabled = false;
		exitText.enabled = false;
	}

	public void NoPress()
	{
		quitMenu.enabled = false;
		instructionMenu.enabled = false;
		startText.enabled = true;
		instructionText.enabled = true;
		exitText.enabled = true;

	}

	public void StartLevel()
	{
		Application.LoadLevel (1);
	}

	public void ExitGame()
	{
		Application.Quit ();
	}
	

}

In your ExitPress function your showing both menus:

     public void ExitPress()
     {
         quitMenu.enabled = true;
         instructionMenu.enabled = true;
         ...
     }

And since that’s the only function that sets the menus to true I guess you registered that function to both buttons.

Try splitting that function in 2, each one setting only one menu to true, and register each one to a different button.

And a little suggestion, all those “GetComponent” lines in the Start method are useless, you can remove them. You already have a reference to Canvases and Buttons so you don’t need to get the Canvas and Button components of those references.

Try lowering the height of the buttons or moving them further away from each other because it’s possible that the buttons overlap which would cause this problem.