- Home /
Question by
$$anonymous$$ · Jun 08, 2015 at 07:26 AM ·
androidtouchcontrols
Unity Android Touch Controls UP DOWN LEFT RIGHT
I made a game for windows but now i want to made it for android for that, i need a c# script to control my player that is inside a Gameobject. I need the controls for up down left and right to test on my android device. My windows version control script is below: Can someone explain how to create a script to add touch controls (up down left right)
using System.Collections;
public class controlodejogador : MonoBehaviour {
public GameObject player;
public float AlturaMaxima;
public float AlturaMinima;
public float speedY;
public float speedX;
public int pontuaçao;
public int score;
public TextMesh pontos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float translationY = Input.GetAxis ("Vertical") * speedY;
float translationX = Input.GetAxis ("Horizontal") * speedX;
player.transform.Translate (translationX, translationY, 0);
if (player.transform.position.y > AlturaMaxima) {
player.transform.position = new Vector2 (player.transform.position.x,AlturaMaxima);
}
if (player.transform.position.y < AlturaMinima) {
player.transform.position = new Vector2(player.transform.position.x,AlturaMinima);
}
Comment
Have a look at the API of Unity
Have a look at TouchPhase as it give you idea about setting up control on android.
You can write the control for android on a new script or you can write that on your existing script. Use something call RuntimePlatform if the latter choice are made.
Your answer
![](https://koobas.hobune.stream/wayback/20220613200701im_/https://answers.unity.com/themes/thub/images/avi.jpg)