Quitting a game through GUI

Hey guys, I’m struggling a bit as I’ve created a GUI and three buttons, one to start and another to take you to another scene and the problem I’m having is the quit button as it has the following code:

	if(GUI.Button(Rect(595,473,186,72),"Quit"))
   
{

		Application.CancelQuit(); 

}

I’ve done the exact same as the other two but for some reason it won’t quit the game/application even when I build and run the game, am I doing something wrong?

Thanks in advance!

Application.Quit() is the code to exit the game. Application.CancelQuit() does just what it says, it cancels the Quit call.

In this case you want to replace the line ‘Application.CancelQuit()’ with ‘Application.Quit()’, as the function CancelQuit does just that – cancels any quitting operations that have been already put in motion. If you do that, your button should work. :wink: