Script Two Button Functions At Once

Hi all!

I am having some difficulty getting a cyclical (as in works for two buttons that toggle the other) button toggle to work. This bit of code will successfully find both objects whether or not they are active (the Debug always returns the correct status of the corresponding UI elements,) and can go from MainMenu → OptionMenu, but will not work the opposite way around. I checked to be sure that everything was linked properly in the editor and each UI element is virtually the same as the other.

	public GameObject MainPanel;
	public GameObject OptionPanel;

	void Start()
	{
		// Find inactive GameObjects by finding their parent then their child
		MainPanel = GameObject.Find ("Canvas").transform.Find ("MainMenuPanel").gameObject;
		OptionPanel = GameObject.Find ("Canvas").transform.Find ("OptionsPanel").gameObject;

		string MainStatus = MainMenuUp ().ToString ();
		string OptionStatus = OptionMenuUp ().ToString ();

		Debug.Log ("Option Menu is: " + OptionStatus);
		Debug.Log ("Main Menu is: " + MainStatus);
	}

	public void OnClickToggle()
	{
		if (OptionMenuUp () == true) {
			MainPanel.SetActive (true);
			OptionPanel.SetActive (false);
		}

		if (MainMenuUp () == true) {
			MainPanel.SetActive (false);
			OptionPanel.SetActive (true);
		}
	}

	bool MainMenuUp ()
	{
		return MainPanel.activeInHierarchy;
	}

	bool OptionMenuUp ()
	{
		return OptionPanel.activeInHierarchy;
	}

Is it impossible to link this script to two different buttons to have them activate/inactivate each other at the same time? Or is there something I missed with my code? Any info will help

Try using an else-if like so instead of two separate if’s.

         if (OptionMenuUp () == true) {
             MainPanel.SetActive (true);
             OptionPanel.SetActive (false);
         } else  if (MainMenuUp () == true) {
             MainPanel.SetActive (false);
             OptionPanel.SetActive (true);
         }