How to quit game in unity
https://docs.unity3d.com/ScriptReference/Application.Quit.html
I have tried the above link but it's not working.
Please confirm the function is actually getting called. A Debug.Log("called"); line inside the sample's if-statement should do this.
Application.Quit() definitely works, so please show your code.
Answer by TBruce · Aug 07, 2016 at 10:55 PM
Application.Quit() does not work while in the Unity editor. If you are running the game in the Unity editor use UnityEditor.EditorApplication.isPlaying = false;
Here is a function that I commonly use
public void QuitGame()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
Nice, I didn't know that this was exposed. Thanks for sharing.
@Addyarb Please mark the correct answer so the topic gets closed as "solved"
I would if I was the OP ;) Just pointing out that this is a nice method to use in-editor.
Application.Quit(); works for standalone game and UnityEditor.EditorApplication.isPlaying = false; works for editor. Now I understood. Thanks for your reply.