converting mouse click and keyboard key to touch gesture

Hi. how can i convert this to touch i want to play it on mobile device

#pragma strict

var moveUp : KeyCode;
var moveDown : KeyCode;

var speed : float = 10;

function Update ()
{
    if (Input.GetKey(moveUp))
    {
        rigidbody2D.velocity.y = speed;
    }
    else if (Input.GetKey(moveDown))
    {
        rigidbody2D.velocity.y = speed *-1;
    }
    else
    {
        rigidbody2D.velocity.y = 0;
    }
    rigidbody2D.velocity.x = 0;
}

You can use the Cross Platform Input package from standard assets to easily implement mobile controls. Just grab one of the control prefabs and add it to your scene, then instead of just having Input.GetKey() you use CrossPlatformInputManager.GetKey().
Don’t forget to import UnityEngine.StandardAssets.CrossPlatformInput though

1 Like