0

I've been trying to find the answer to this with no look, I want to exit a unity game window (build not the game preview in the developer) here is a snippet of my code,

 void Update()
    {
        if (Input.GetKeyDown (KeyCode.Escape)) {
            Application.Quit();
        }

    }

This doesn't exit the window and I cant see why, any ideas? Thanks for any reply.

Steven
  • 166,672
  • 24
  • 332
  • 435
tomahawx
  • 15
  • 1
  • 4
  • Sorry, im new to unity, this is my first game and im not familier with c#, how would i do that? – tomahawx Oct 23 '14 at 18:03
  • Just to make sure, it is finding the method ok and everything, right? Your program is going through it? – Dylan Corriveau Oct 23 '14 at 18:03
  • The rest of the code works but when I press escape nothing happens, even in console. – tomahawx Oct 23 '14 at 18:04
  • 1
    Just to ensure that the event isn't getting swallowed, can you use http://docs.unity3d.com/ScriptReference/Debug.Log.html to log a message to verify that you're intercepting the Escape key? – Sean Duggan Oct 23 '14 at 18:26

2 Answers2

0

Try using the example given for Application.Quit in the documentation

void Update() 
{
    if (Input.GetKey("escape"))
    {
        Application.Quit();
    }        
}
Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
0

OK I used what Dylan Corriveau said but to no luck, so i tried making a Js file and used the example from unity documents and it works now, thanks.

tomahawx
  • 15
  • 1
  • 4