- Home /
Question by
ShroomWasTaken · Feb 26, 2015 at 02:21 PM ·
javascriptguiinputpause menuescape
Pause Menu won't open...
So, i have my script thats a pause menu with some buttons and textures. But it won't open when i hit the "Esc / Escape" key. But it does however open if i click the "MenuActive" variable in the Isnpector. Does anyone know what im doing wrong? #pragma strict
var menuActive : boolean = false;
var pauseMenuTexture : Texture;
function Start () {
}
function Update () {
}
function OnGUI () {
if(Input.GetKeyDown(KeyCode.Escape) && menuActive == false) {
menuActive = true;
}
else if (Input.GetKeyDown(KeyCode.Escape) && menuActive == true) {
menuActive = false;
}
if (menuActive == true) {
GUI.DrawTexture(Rect(0, 0, 9000, 9000), pauseMenuTexture);
GUI.Label(Rect(10, 10, 500, 500), "Pause Menu");
GUI.Button(Rect(10, 30, 80, 30), "Resume");
GUI.Button(Rect(10, 50, 80, 30), "Options");
GUI.Button(Rect(10, 70, 80, 30), "Exit Game");
}
}
Comment
Best Answer
Answer by SirMalarkey · Feb 26, 2015 at 03:03 PM
Your Input code should be done in Update not OnGUI
var menuActive : boolean = false;
var pauseMenuTexture : Texture;
function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.Escape) && menuActive == false) {
menuActive = true;
}
else if (Input.GetKeyDown(KeyCode.Escape) && menuActive == true) {
menuActive = false;
}
}
function OnGUI () {
if (menuActive == true) {
GUI.DrawTexture(Rect(0, 0, 9000, 9000), pauseMenuTexture);
GUI.Label(Rect(10, 10, 500, 500), "Pause Menu");
GUI.Button(Rect(10, 30, 80, 30), "Resume");
GUI.Button(Rect(10, 50, 80, 30), "Options");
GUI.Button(Rect(10, 70, 80, 30), "Exit Game");
}
}
Oh wow, i didn't even realize i did that! Thank you!
Your answer
Follow this Question
Related Questions
Pause Menu controlled by keys 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Joystick ellipse movement (2d mobile asset modification) 1 Answer
Need help using GUI.Button/ input storage 1 Answer
Text.Field erratically updating 0 Answers