I am creating some samples for android. How to quit the game with the “exit” button?
I tried using the following code:
# pragma strict
function Update () {
if (Input.GetKey (KeyCode.Escape)) {
Application.Quit ();
}
}
To exit the game I need to go into task manager and stop the process.
Someone help me?
Try this one:
function Update()
{
if (Input.GetKeyDown(KeyCode.Escape ))
{
Application.Quit ();
}
}
It wouldn’t make a difference putting it in OnGUI or Update.
Well, there is a difference. You should never use Input class in OnGUI. OnGUI is an event processing callback which gets called several times per frame. Try “Event” class in case of using OnGUI. And “Input” should only be used in Update() or LateUpdate() functions.
I meant it wouldn’t fix her problem if you put it in OnGUI or Update…
yep you’re right, well I guess it should work the way it is… anyway remember that Application.Quit() doesn’t quit the app in the editor or in the web player…