x


how to add a dialog box when quit is opted

when quit is opted i want a dialog-box to appear saying "are you sure you wanna quit. yes/no" if no is chosen then i want the game to quit other wise i want the game to resume. how do i program it. i do not know much of programming.

please help

thanks!

more ▼

asked Jan 30 '12 at 08:52 AM

BLISS gravatar image

BLISS
1 3 8 10

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

1 answer: sort voted first

Go to gameobject => create other => 3dText. Create the text you want and got to component=>physics=>boxcollider. Make sure you text is not inside another object as it will show but you won't be able to touch it. Then assign that script below to the GUI object and you are good to go.

var GuiOn = false;
//Those 2 fcts are just to change the color of your word when you hover the mouse
over them
function OnMouseEnter(){
    renderer.material.color = Color.green;
}
function OnMouseExit(){
    renderer.material.color = Color.white;
}
function OnGUI () {         
        if(GuiOn){//check if gui should be on. If false, the gui is off, if true, 
        the gui is on
           // Make a background box
           GUI.Box (Rect (10,10,100,90), "You sure?");
           // Make the first button. If pressed, quit game 
           if (GUI.Button (Rect (20,40,80,20), "Yes")) {
             Application.Quit();
           }
           // Make the second button.If pressed, sets the var to false so 
            that gui disappear
               if (GUI.Button (Rect (20,70,80,20), "No")) {
                 GuiOn=false;
               }
            }
        }
        //fct checks for a click and sets the var to true to make gui appear.
        function OnMouseDown(){
            GuiOn = true;
        }

Now you need to start tweaking the variable to place properly and do exactly what you want.

Hope that helps

more ▼

answered Jan 30 '12 at 08:32 PM

fafase gravatar image

fafase
10.5k 9 15 41

I wanted to post pictures to show the process but I could not...

Jan 30 '12 at 08:32 PM fafase

HEY THANX!! :)

Jan 31 '12 at 04:39 AM BLISS

i've this code which opens a gui when i press esc while playing. i want another gui to open which asks for "are you sure you wanna quit " when quit is chosen. how do i do that?

var guiSkin: GUISkin;

var nativeVerticalResolution = 1200.0;

var isPaused : boolean = false;

var isquit : boolean = false;

function Update() {

if(Input.GetKeyDown("escape") && !isPaused)

{ print("Paused");

Time.timeScale = 0.0;

isPaused = true;

}

else if(Input.GetKeyDown("escape") && isPaused)

{

print("Unpaused");

Time.timeScale = 1.0;

isPaused = false;

} }

function OnGUI ()

{

// Set up gui skin

GUI.skin = guiSkin;

}

if(isPaused) { GUI.Box (Rect (380,200,300,300), "");

// RenderSettings.fogDensity = 1;

if(GUI.Button (Rect((Screen.width)/2,280,140,70), "Quit", "button2"))

{

if(isquit)

{

print("Quit!");

Application.LoadLevel("main menu"); }

if(GUI.Button (Rect((Screen.width)/2,360,140,70), "Restart", "button2")) {

print("Restart"); Application.LoadLevel("SomeLevelHere");

Time.timeScale = 1.0; isPaused = false; }

if(GUI.Button (Rect((Screen.width)/2,440,140,70), "Continue", "button2")) {

print("Continue"); Time.timeScale = 1.0; isPaused = false;
}

}

}

@script AddComponentMenu ("GUI/Pause GUI")

Jan 31 '12 at 06:42 AM BLISS
(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:

x52

asked: Jan 30 '12 at 08:52 AM

Seen: 1121 times

Last Updated: Jan 31 '12 at 06:52 AM