Created
October 24, 2020 03:53
-
-
Save andarms/598580648780cf40e5e618e99b2bca67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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