In my game there is a pause, which is called by the "Esc" key .

enter image description here

After the defeat, a layer pops up on top of the game that says "Game Over" .

enter image description here

Since this is a layer, not a new scene, the pause can work at the time of Game Overa .

Question: how to block Esc and then restore it? Any enabled ?

LifeManager Script:

void Update () { if (lifeCounter == 0) { gameOverScreen.SetActive(true); player.gameObject.SetActive(false); } theText.text = "x " + lifeCounter; if (gameOverScreen.activeSelf) { //тут блокируем клавишу *"Esc"*. waitAfterGameOver -= Time.deltaTime; } if(waitAfterGameOver < 0) { //тут разблокируем клавишу "Esc". Application.LoadLevel(mainMenu); } } 

Script PauseMenu:

 using UnityEngine; using System.Collections; public class PauseMenu : MonoBehaviour { public string levelSelect; public string mainMenu; public bool isPaused; public GameObject pauseMenuCanvas; // Update is called once per frame void Update () { if (isPaused) { pauseMenuCanvas.SetActive (true); Time.timeScale = 0f; } else { pauseMenuCanvas.SetActive(false); Time.timeScale = 1f; } if(Input.GetKeyDown(KeyCode.Escape)) { isPaused = !isPaused; } } public void Resume() { isPaused = false; } public void LevelSelect() { Application.LoadLevel (levelSelect); } public void Quit() { Application.LoadLevel (mainMenu); } } 
  • one
    Well, in general, the standard and primitive saaaaaaam mechanism is the isGameOver flag, which you do true / false when you need ..... and accordingly where you process the ESC key, write: if (isGameOver) return; that's all ...... - Alexey Shimansky
  • @ AlekseyShimansky Useful, but this is for myself ...) If I use your advice. - Artik Slayer
  • Do you think there is a better option?)) You also need a condition under which ESC does not work ... here it is the same condition. - Alexey Shimansky
  • Can you show (add to the question) the code block where the ESC processing goes? is it in Update going on? - Alexey Shimansky
  • No, seriously, what exactly hinders not to handle pressing if the game is over? - eastwing

1 answer 1

I see 2 ways:

  1. Boolean isGameOver

  2. In processing where Esc is processed, check whether Visible (Enabled?) is not gem overscreen.

But better boolean.