- Home /
Make a UI button quit the exe, Unity 5
Hi,
I am fairly new to Scripting and Unity so please excuse my lack of knowledge !
I Have created a 'quit' button in the UI and a quit script which is attached to the 'quit' button. My quit script is as follows:
#pragma strict
import UnityEngine.UI;
public function ClickExit () {
Application.Quit();
}
I use the OnClick()and select my ClickExit function, but it doesn't quit. I have added a debug function to print a text message which calls fine from the OnClick so I know the button is working. I have also created a build and it still doesn't quit. If someone could please help me with this that would be majic
Application.Quit() is not working in the Editor. try making a build and run the build exe.
it works fine... i use this for my android app... i think its an easy way to quit a game...
sorry for my bad english...
maeby is a bit late but, it's better not to use this in android or IOS since the stores dont like people using the function Application.Quit(); and could take your app out of the store for this motive
Answer by AceScottie · Mar 26, 2015 at 11:09 AM
not sure it this will help but in my GUI i have it as a keydown event with an if statement
if (Input.GetKeyDown(KeyCode.Escape)) {
Application.Quit();
}
you should try use an If statement
public function ClickExit() {
if (GUI.Button //your button here) {
Application.Quit();
}
}
hope this helps but i also did mine using c# not js
Answer by homph · Apr 08, 2015 at 03:01 PM
Many thanks for your help. In the end I noticed that Unity wasn't updating my UI layout when I was creating a build, so I restarted my machine, Unity ! Created a new Canvas and the Quit button worked !
Don't forget to mark your question as resolved by clicking on the check mark of your own answer ! ;)