3
I’m learning Unity
and would like to know what the command to exit the game, ie close the application and also to know this command as I apply to press the back button of mobile Android
execute such a command.
3
I’m learning Unity
and would like to know what the command to exit the game, ie close the application and also to know this command as I apply to press the back button of mobile Android
execute such a command.
5
In C# you can do the following:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Update() {
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
}
}
3
In the Unity
, there are parameters like the Escape
which are customized for the software to be really universal. You can see all the keys supported on Unity documentation.
What would Escape be?
The key (Esc) was created by Bob Bemer. It is labeled
Esc
orEscape
and is generally used to generate the escape characterASCII
, whose number is27
. This character is usually used for generate an escape sequence. It typically lies in the corner top left keyboard. Its use is continuous for small boxes Microsoft Windows dialog, which equates to responses like:Não, Remover, Exit, Cancelar ou Abortar
.
Therefore, in mobile devices this key would correspond to the key voltar
, whether it’s Android, Windows or iOS.
Already to make the application output in Unity we use Application.Quit();
, that according to its own documentation has the objective: "Close the game application.".
Now in code how can we do this?
C#
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Update() {
if (Input.GetKey("escape"))
Application.Quit();
}
}
Javascript:
function Update () {
if (Input.GetKey ("escape")) {
Application.Quit();
}
}
References: Unity 3D Documentation
Browser other questions tagged c# android unity3d
You are not signed in. Login or sign up in order to post.
confirm if this is the condition mentioned in your code is the back button of the device ?
– Vale
I have no android to test here, but from what I remember and what I searched on the internet, yes, that’s right.
– Antonio Carlos
ok I’ll test now
– Vale
is that it worked out well worth beast
– Vale