- Home /
you leave a question by pressing a button?
I want to press the button "exit" button or the "new game" to come out if you really want to go out or want to start a new game.
That leaves a question whether I really want to do that action.
I feel my English is that I use the translator.
Answer by kevinseligmann · Apr 17, 2012 at 08:01 PM
Are you trying to make a GUI with those two buttons? If that's the case, for an exit button you could use:
if (GUI.Button(Rect(10,10,50,30),"Click"))
Application.Quit();
And for the New Game button well, are you working with scenes? Here's a little help about changing scenes from http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html
Hope that helps!
Think (s)he's wanting an action confirmation pop-up of some sort. Like when you try to "Exit" , it then asks, "Are you sure you want to exit?" and you have to confirm it.
Yes, after he answered this question I realized he ment that. @T27$$anonymous$$ already posted an answer with the script, let's find out if that was what he was after.
Answer by nagro · Apr 17, 2012 at 08:30 PM
if no button I have it done but what I need is pressing x button as you leave a window that says "want to get out of this game? Yes____NO"
Answer by T27M · Apr 17, 2012 at 09:58 PM
var exit : boolean = false;
var quit : boolean = false;
function OnGUI ()
{
if(!exit && !quit && GUI.Button(Rect(0,0,100,100),"Quit Game"))
{
quit = true;
}
if(quit)
{
GUI.Label(Rect(130,0,200,100),"Would You like to quit the game?");
if(GUI.Button(Rect(120,20,100,100),"Yes"))
{
exit = true;
quit = false;
}
if(GUI.Button(Rect(230,20,100,100),"No"))
{
quit = false;
}
}
if(exit)
{
GUI.Label(Rect(130,0,200,100),"Are you sure?");
if(GUI.Button(Rect(120,30,100,100),"Im Sure"))
{
Application.Quit();
Debug.Log("Quit the game");
}
if(GUI.Button(Rect(230,30,100,100),"No,Wait!"))
{
exit = false;
}
}
}
I'm still new to unity but this works. Any critiques welcome.
I have the same problem! How can i interact with three window's buttons?
Your answer
Follow this Question
Related Questions
Switch Camera On Button Press? 2 Answers
Animation pause on button press? 1 Answer
A node in a childnode? 1 Answer
Quit button 1 Answer
Play sound on button press? 1 Answer