Exit game in Unity
Objective: Allow the user to exit the game or application with the touch of a button
Allowing the user to quit your app or game is a vital part of development as it makes your app user friendly and easy to use.
This is one of the most simple parts of Unity and is really easy to implement.
In my endless runner DangryRun, I have a some buttons on the interface that allows the user to open different panels and 1 button exits the game.
First, make a public void method:
Making the method public allows you to call it in a button click inside the unity editor.
You will need to set up your buttons to run the method when it is clicked.
The line of code that quits the game is:
Application.Quit();
And that’s it, that line will allow the user to quit the application. You can use this anywhere, it could be linked to a certain key press as well.
I need to also mention that when trying this functionality out in the Unity editor, it will not work. You will need to build out a version of your project.
Come back for more articles in game development in Unity.