Back Button menu navigation issue

Hi! Im having this little issue where the back button terminates the program when its supposed to navigate to a different screen.

Im using ngui and i simply do
NGUITools.SetActive(mainscreen,false); when navigating through menus.

It navigates perfectly when the Application.Quit code is omitted. But when its added, it terminates the game on any screen. I think it may be running twice.

	void NavigateBack()
	{
		if (Input.GetKeyDown(KeyCode.Escape)) 
		{
			if(ms != MenuScreen.Main)
			{
				BackClick();
			}
			else
			{
				Application.Quit();
			}
		}
	}

The method is run in Update()

Any suggestions?

Make sure ur if else condition is right. I feel it is going to else condition. Write debug and check.

It actually wont even print anything. I even tried if (Input.GetKeyDown(KeyCode.Escape)) { print("Got Here"); } It only navigates back if i put the code inside the if. but then i cant terminate the program with the back button without another condition.

1 Answer

1

I figured it out. Unity is sometimes a little buggy and i was forced to create a second script and call the methods and variables in the first script.

Heres the second script

using UnityEngine;
using System.Collections;

public class NavigateBack : MonoBehaviour {
	
	private GameObject mainmenu;
	
	// Use this for initialization
	void Start () 
	{
		mainmenu = GameObject.Find("Main Camera");
	}
	
	// Update is called once per frame
	void Update () 
	{
		Navigate();
		
	}
	
	void Navigate()
	{
		if (Input.GetKeyDown(KeyCode.Escape) && MenuUI.ms != MenuUI.MenuScreen.Main) 
		{
			mainmenu.GetComponent<MenuUI>().BackClick();
		}
		else if (Input.GetKeyDown(KeyCode.Escape) && MenuUI.ms == MenuUI.MenuScreen.Main)
		{
			Application.Quit();
		}
	}
}