3
\$\begingroup\$

i am android programmer and i want control button input in android for example i made a game that when you press back button in android mobile nothing happens but i want quite from game.

enter image description here enter image description here

This is how you can use the android back button in Unity games.

In C#

void Update()
{
   if (Application.platform == RuntimePlatform.Android)
   {
    if (Input.GetKeyDown(KeyCode.Escape)) 
        Application.Quit();
   }
}

or in JS

function Update()
{
   if (Application.platform == RuntimePlatform.Android)
   {
    if (Input.GetKeyDown(KeyCode.Escape)) 
        Application.Quit();
   }
}

but how i can contorl other buttons

\$\endgroup\$
1
\$\begingroup\$
function Update () {
    if (Input.GetKey(KeyCode.Home)){
        // Home button pressed
        // Write everything you want to do here
    }
    if (Input.GetKey(KeyCode.Escape)){
        // Escape button pressed
    }
    if(Input.GetKey(KeyCode.Menu)){
        Application.Quit();
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.