x


Pause With an exit button?

how would i make it so that when i pressed lets say 'P' it pauses the game and a button pop up saying exit and obviously when you hit exit it exits the the menu and when you hit 'P' again the menu disappears if anybody could help me it would be a big massive help, I have try this code below but all it does is exit the game an start

function Update () {

       if(Input.GetKey("p"))

 GUI.Button(Rect(20,20,100,30),"Exit")

    Application.LoadLevel("Main Menu");

}

im doing a school project and i need it done soon :( and if you like i would put you in the credits ?

more ▼

asked Jan 15 '12 at 11:50 AM

benjimazza gravatar image

benjimazza
102 23 34 37

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

2 answers: sort voted first

Alright when you press "P" you should have the button appear, not the Application.LoadLevel stuff because that loads the level when you press "P". When you press "P" you should set the timescale to 0 and instantiate a button. On the button you should have a script with a OnMouseDown function and have that have the Application load stuff. If you have any questions just ask I'll be happy to help.

more ▼

answered Jan 15 '12 at 03:59 PM

Posly gravatar image

Posly
376 34 41 44

i know this sounds really cheeky but could you put that in to some sort of code because im not a coder as you can see :P so could you please help ??

Jan 15 '12 at 04:53 PM benjimazza

If you are not a coder. Why are you coding then? :P

Jan 15 '12 at 05:40 PM OrangeLightning

its always good to try, I know the smallest bit of code but not loads :P

Jan 15 '12 at 06:33 PM benjimazza
(comments are locked)
10|3000 characters needed characters left
private var paused = false;

function Update(){
    if(Input.GetKeyDown("p")){
        if(paused){
            paused = false;
            Time.timeScale = 1;
        }else{
            paused = true;
            Time.timeScale = 0;
        }
    }
}

function OnGUI(){
if(paused){
    if(GUI.Button(Rect(Screen.width/2-75,Screen.height/2-15,150,30),"Exit to menu")){
        Application.LoadLevel("Main Menu");
        }
    }
}

This script draws a button when the game is paused(press "p") and if you click it, it will load the Main Menu.

A basic example. I am not keen doing your homework, but I hope you'll learn something from this.

Code is not tested and is meant as an example.

more ▼

answered Jan 15 '12 at 05:45 PM

OrangeLightning gravatar image

OrangeLightning
5.4k 47 57 112

this works perfect :) thanks,,, erm its not actually homework :D it sounds that way because it was for school but its not homework :) although you might not want to be im putting you in the credits because you wrote this code :L might sounds sad but thanks

Jan 15 '12 at 06:38 PM benjimazza

No, problem señor ;) I wish we had projects like this at my school.

Jan 15 '12 at 07:20 PM OrangeLightning

So are you cool with me putting you in the credits, and well.. get a petition or something going :P (to be able to do projects like this at your school) ;-)

Once again, thank you.

Jan 15 '12 at 08:06 PM benjimazza
(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:

x535
x160

asked: Jan 15 '12 at 11:50 AM

Seen: 807 times

Last Updated: Jan 15 '12 at 08:06 PM