- Home /
How to close a GUI window
Hello again everyone,
I'm trying to make a pause menu for my game, and i have it done except for one thing, i can't get my resume game button to work. So the question here is how to i make it when i press the button, the GUI box closes and the timescale go back to normal? I've looked all over the scripting reference page but found nothing, help is greatly appreciated.
-edit- Ok, heres my code(new code actually) which still doesn't work
function OnGUI() { if (Input.GetButton("Esc")) pause if (paused) { GUI.Box (Rect (500,500,105,90), "Pause Menu"); Time.timeScale = 0
if (GUI.Button (Rect(250, 250, 40, 25), "Resume")) {
paused = false;
}
}
}
Answer by Stelimar · Nov 29, 2009 at 03:14 AM
It's hard to tell without seeing your existing code, but I would think it you would want something like this:
function OnGUI() {
if (paused) {
//Code to draw window...
if (/* Function call for resume button */) {
paused = false;
}
}
}
Answer by WarKarma · Feb 10, 2010 at 03:46 PM
This is how i did my pause in game. Hope it will help you.
if(Input.GetKeyDown("p")) //checking if P button was pressed
{
if(Time.timeScale == 1) //if game was not paused it will pouse the game
{
audio.volume = 0.1; //making music volume in background to be lower print("Pause"); //for testing only Time.timeScale = 0; //pousing the game
}
else if(Time.timeScale == 0) //if game was paused it will start the game
{
audio.volume = 0.5; //making music volume in background to be louder print("Start"); //for testing only Time.timeScale = 1; // continuing the game
}
}
even though you spaced it out so that it's kinda readable, you could format that so we can truely read it... just press the button with the numbers on it.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Destroy a Game object on collision and add it to my Gui??? 1 Answer
PasswordField help. 1 Answer
How to make a monolgue? 1 Answer