Trying to quit

Hi there - running unity 5.6
I have a UI with 2 buttons, one to load the level and one to quit the game.
I have added debug prints to ensure the code I have attached to the buttons gets called - it does.

It doesnt load the level OR exit the game when I run from within unity.

However if i build and run then the level is loaded or the game quits.

WHY? I really would like to test within unity rather than compile and build every time I want to test something.

Cheers
C

Check that the scenes are added to your build settings.

Application.Quit() is ignored within the editor. It wouldn’t make much sense if it wasn’t.

This. And not just the editor, there are a couple other platforms that have their own way of quitting, and ignore Application.Quit().

So if it is ignored when I press the play button how do i test it? I was hoping it would just be the same as pressing the play button again to stop running my code.

Throw in a Debug.Log right next to it. Then you’ll see a message in the console each time it’s called.

Just do this in your quit function;

    public void Quit()
    {
        #if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
        #else
            Application.Quit();
        #endif
    }
3 Likes