Skip to content

Instantly share code, notes, and snippets.

@andarms
Created October 24, 2020 03:53
Show Gist options
  • Save andarms/598580648780cf40e5e618e99b2bca67 to your computer and use it in GitHub Desktop.
Save andarms/598580648780cf40e5e618e99b2bca67 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class TouchMovement : MonoBehaviour
{
public float Speed = 0.4f;
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
float screenHalf = Screen.width / 2;
Vector3 movement = Vector2.zero;
if (touch.position.x > screenHalf)
{
movement = Vector2.right;
}
else
{
movement = Vector2.left;
}
this.transform.position += movement * this.Speed * Time.deltaTime;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment