Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TouchMove()
- {
- if (Input.touchCount > 0)
- {
- Touch touch = Input.GetTouch(0);
- float middle = Screen.width / 2;
- if (touch.position.x < middle && touch.phase == TouchPhase.Began)
- {
- MoveLeft();
- }
- else if (touch.position.x > middle && touch.phase == TouchPhase.Began)
- {
- MoveRight();
- }
- }
- else
- {
- SetVelocityZero();
- }
- }
- public void MoveLeft()
- {
- rb.velocity = new Vector2(-playerSpeed, 0);
- }
- public void MoveRight()
- {
- rb.velocity = new Vector2(playerSpeed, 0);
- }
- public void SetVelocityZero()
- {
- rb.velocity = Vector2.zero;
- }
- }
Add Comment
Please, Sign In to add comment