- Home /
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?
$$anonymous$$ake 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.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
{
print("Got Here");
}
It only navigates back if i put the code inside the if. but then i cant ter$$anonymous$$ate the program with the back button without another condition.
Answer by Gucci Gagan · Nov 28, 2013 at 05:03 AM
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();
}
}
}
Your answer
Follow this Question
Related Questions
Setting Background using NGUI 0 Answers
How to deactivate an NGUI panel, but not hiding it. 4 Answers
iTween issue creating a gui. menu box 1 Answer
How to make a GUI appear and disappear with the same button? 1 Answer
ngui anchor alignment 1 Answer