Ragnar Lodbrok Ragnar Lodbrok - 10 months ago 95
iOS Question

Unity general close button C#

I'm writing a C# code in Unity 5.3.4. I've been trying to develop a button that will close the app be it when I test it on my computer or when I'm in Android or iOS.

For android I've found this code and it's working:

if (Application.platform == RuntimePlatform.Android) {
if (Input.GetKeyUp(KeyCode.Escape)) {
//quit application on return button

This exits the code if you press the return button. I've develop a function that gets called when you press the exit button and it calls Application.Quit(). The problem is that this does nothing when I'm testing the code in my computer.

Is there a more generic way of closing an APP in unity, independently of the platform where you run the APP?


Use UnityEditor.EditorApplication.isPlaying = false; for stopping game in editor.

Use System.Diagnostics.Process.GetCurrentProcess().Kill(); if you even want to quit Unity as well as the app in all devices.

But Application.Quit () works on most devices without issue. It's not an editor method to call.