C
C#2mo ago
ULTIMA

Quit Game Button

ive made the button and used the code
public void QuitGame() { Application.Quit(); Debug.Log("Quit the game"); } the debug to make sure the button is calling the function, and it is. but it doesnt end the game at all in unity? any ideas why?
2 Replies
Buddy
Buddy2mo ago
Application.Quit() don't work in editor because there is no app to begin with You need to use a preprocessor to stop it if you use the editor
#if UNITY_EDITOR
if(EditorApplication.isPlaying)
{
UnityEditor.EditorApplication.isPlaying = false;
}
#else
Application.Quit();
#endif
#if UNITY_EDITOR
if(EditorApplication.isPlaying)
{
UnityEditor.EditorApplication.isPlaying = false;
}
#else
Application.Quit();
#endif
ULTIMA
ULTIMA2mo ago
ah ok thanks