Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 1 down vote accepted
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();
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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