how do i move my player left and right using touch pad?

Hello everyone!

I am working on a 2d game for android. however i really can’t seem to find out how to use a touchpad. I would like to have it so that if the x value increases my player goes one direction if it decreases the other direction. I really can’t seem to find out how to do it. if you would be so kind to tell me what script goes on what item aswell that would be wonderfull.

Thanks in advance.

#pragma strict
//Variables…

var speed=0.05f;

function Start () {

}




function Update () {

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
transform.Translate (touchDeltaPosition.x *speed,0,0);



}



}