Thursday, October 18, 2018

unityscript - How i can control button input android?


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



Answer



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();
}
}

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...