- Home /
 
 
               Question by 
               CrashCZ · Sep 04, 2017 at 08:36 AM · 
                pausepause menukeyspause gameescape  
              
 
              Escape key not working
Hello. I hava a problem with my pause menu. I want to open it when escape key is pressed but it does nothing. I tried another keys and it worked so i don't know where the problem is.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class myPause : MonoBehaviour
 {
     bool isPaused;
     public GameObject Pause;
 
     void Start()
     {
         isPaused = false;
         Pause.SetActive(false);
     }
 
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Escape) && isPaused == false)
         {
             Pause.SetActive(true);
             isPaused = true;
         }
         if (Input.GetKeyDown(KeyCode.Escape) && isPaused == true)
         {
             Pause.SetActive(false);
             isPaused = false;
         }
     }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Imankit · Sep 04, 2017 at 09:14 AM
You need to put else if -
   if (Input.GetKeyDown(KeyCode.Escape) && isPaused == false)
      {
          Pause.SetActive(true);
          isPaused = true;
      }
      else if (Input.GetKeyDown(KeyCode.Escape) && isPaused == true)
      {
          Pause.SetActive(false);
          isPaused = false;
      }
 
              Your answer
 
             Follow this Question
Related Questions
Pause Game Through Button UI Click Instead of Escape Key? 2 Answers
Pause Game 1 Answer
How to make a pause menu with Gui Texture?? 2 Answers
Game stays paused after Restart. 1 Answer