Hello!
I have game on windows. And in my code I have:if (Input.GetKeyDown("up") && up())
, how to change this to work on android game? My first idea is created arrows(buttons) on ui, but how do this? Please help!
I don’t know what ‘up()’ is but you could replace that if statement with a method. The method could be called from your UI button.
How will this appeal look more or less like?
Let’s say you had :
if(Input.GetKeyDown(KeyCode.W)) {
Vector3 pos = transform.position;
pos.y += speed * Time.deltaTime;
transform.position = pos;
}
And you wanted to move that to a button, you could write a method for the button’s OnClick event.
public void MoveUp() { // must be public for the OnClick event.
Vector3 pos = transform.position;
pos.y += speed * Time.deltaTime;
transform.position = pos;
}
Is that what you were asking?
You could even change the first snippet to :
if(Input.GetKeyDown(KeyCode.W)) {
MoveUp();
}