- Home /
 
"Escape" not working to open menu?
Hey guys! I have another (hopefully) easy question to answer. For some reason, the menu does not open when I press "Escape", but closes when I press "Escape" and its already open. Anybody know why?
 public bool isInMenu;
     
     // Update is called once per frame
     void Update () 
     {
     if(Input.GetKey(KeyCode.Escape) && isInMenu == false && NetworkManager.Instance.MyPlayer.IsAlive == true)
     {
     isInMenu = true;
     Debug.Log("Menu Opened");
     }
     if(Input.GetKey(KeyCode.Escape) && isInMenu == true && NetworkManager.Instance.MyPlayer.IsAlive == true)
     {
     isInMenu = false;
     Debug.Log("Menu Closed");
     }
     }
     
     void OnGUI()
     {
     if(isInMenu == true)
         {
         InGameMenu();
         }
     }
     
     void InGameMenu()
     {
     if(GUI.Button(new Rect(Screen.width * (0.1f/10f),Screen.height * (0.1f/6.3f),Screen.width/2, Screen.height/2), "Disconnect"))
         {
         Network.Disconnect();
         }
     }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by The Kracken · Dec 02, 2013 at 08:41 PM
Try this code and let me know if it works
 if(Input.GetKey(KeyCode.Escape) &&  NetworkManager.Instance.MyPlayer.IsAlive == true)
 {
   isInMenu = !isInMenu;
 }
 
               That should work as a toggle for the menu. My though would be that maybe the NetworkManager.Instance.MyPlayer.IsAlive might be false for some reason.
Your answer
 
             Follow this Question
Related Questions
Music Slider hookup? 1 Answer
key binding 0 Answers
gameTimer needs to be based on an event, not onGUI 2 Answers
if statement will only execute once 1 Answer