Question by
robomcfobo · Mar 12, 2016 at 07:27 PM ·
c#menuboolean
making a pause menu
when i press escape the menu appear on the screen, but whenever i press escape again, nothing happens. has it something to do with the boolean, or is it that its in the same function?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Pause : MonoBehaviour {
public Canvas PauseCanvas;
public Button Resume;
public Button Settings;
public Button ExitToMainMenu;
public Button ExitToDesktop;
public Canvas SettingCanvas;
public bool isPaused;
// Use this for initialization
void Start ()
{
SettingCanvas.enabled = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
isPaused = false;
PauseCanvas.enabled = false;
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown(KeyCode.Escape) && !isPaused)
{
PauseCanvas.enabled = true;
isPaused = true;
}
if(Input.GetKeyDown(KeyCode.Escape) && isPaused)
{
PauseCanvas.enabled = false;
}
}
Comment
Answer by Positive7 · Mar 12, 2016 at 09:18 PM
Try this :
void Update ()
{
if (Input.GetKeyDown (KeyCode.Escape)) {
if (!isPaused) {
PauseCanvas.enabled = true;
isPaused = true;
return;
}
PauseCanvas.enabled = false;
isPaused = false;
}
}
Your answer
Follow this Question
Related Questions
Need to do multiple boolean check for completing level 3 Answers
I cant call function another script ! 1 Answer
Set bool to be active only when a button and another bool are set 1 Answer
esc key oddity 2 Answers
Unity Swipe menu 0 Answers