x


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;
		}
	}
}
more ▼

asked Nov 29 '09 at 02:31 AM

Will gravatar image

Will
408 8 10 19

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
    	}
    }
}
more ▼

answered Nov 29 '09 at 03:14 AM

Stelimar gravatar image

Stelimar
3k 14 16 50

Ah, got it working, thanks for the help

Nov 29 '09 at 07:14 AM Will
(comments are locked)
10|3000 characters needed characters left

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

}

}

more ▼

answered Feb 10 '10 at 03:46 PM

WarKarma gravatar image

WarKarma
18 2 2 4

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.

Dec 24 '10 at 01:22 AM Jesus_Freak
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5093
x3694

asked: Nov 29 '09 at 02:31 AM

Seen: 2253 times

Last Updated: Nov 29 '09 at 03:58 AM