- Home /
exit button doesn't close application
I'm trying to make a button based text rpg and i have a lot of questions the first being I made a menu for my game with a New game, load, save and quit button.
When i click the exit button, nothing happens, did i do it wrong?
using System.Collections; using System.Collections.Generic; using UnityEngine; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void QuitGame () { Application.Quit (); Debug.Log("Game is exiting"); //Just to make sure its working } }
Answer by Omti1990 · Sep 27, 2018 at 06:27 AM
You probably did nothing wrong, assuming your Debug.Log for exiting is actually being called.
Application.Quit doesn't work in the editor, it only works in the finished build.
So if
Debug.Log("Game is exiting");
is actually causing an entry in your log you only need to build the game if you want to test the exit-button "for real".
Answer by DawidNoras · Sep 27, 2018 at 07:43 AM
If you want to exit playmode in editor with this button, you can call: Application.isPlaying = false;
making code: #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif
Answer by arbazgillani · Sep 27, 2018 at 07:49 AM
use this function void QuitGame() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying=false; #else Application.Quit(); #endif }
Your answer
Follow this Question
Related Questions
Make a UI button quit the exe, Unity 5 2 Answers
Exit button stopped working 1 Answer
How do I set a button to exit a GUI text field 0 Answers
Button doesn't work after build 1 Answer