Can anyone tell me what code to use in Unity for touch buttons in Android?

Started by
0 comments, last by idurvesh 8 years ago

Can anyone tell me what code to use in Unity for touch buttons in Android?

i have made a directional pad. 4 arrow buttons. Up, down, Right, Left.

i brought the 4 image arrows in as canvas image elements names UpImage, DownImage, RightImage and LeftImage. I put the target on them and applied a button component to them.. but i just don't know how to code them to work with touch on android to do the the same functions as the pc keys counterpart (if you were playing on pc ):


using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
    public float SPEED = 0.25f;
    void FixedUpdate()
    {
        var pos = transform.position;

        if (Input.GetKey(KeyCode.LeftArrow)) { pos.x -= SPEED; }
        if (Input.GetKey(KeyCode.RightArrow)) { pos.x += SPEED; }
        if (Input.GetKey(KeyCode.UpArrow)) { pos.y += SPEED; }
        if (Input.GetKey(KeyCode.DownArrow)) { pos.y -= SPEED; }

        transform.position = pos;
    }
}

Can you assist?

Thanks so much

-Line

Advertisement

Have look at this free asset LeanTouch,

https://www.assetstore.unity3d.com/en/#!/content/30111

Works quite well..

This topic is closed to new replies.

Advertisement