Guest User

Untitled

a guest
Jan 11th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. void TouchMove()
  2. {
  3. if (Input.touchCount > 0)
  4. {
  5. Touch touch = Input.GetTouch(0);
  6. float middle = Screen.width / 2;
  7.  
  8. if (touch.position.x < middle && touch.phase == TouchPhase.Began)
  9. {
  10. MoveLeft();
  11. }
  12.  
  13. else if (touch.position.x > middle && touch.phase == TouchPhase.Began)
  14. {
  15. MoveRight();
  16. }
  17. }
  18. else
  19. {
  20. SetVelocityZero();
  21. }
  22. }
  23.  
  24. public void MoveLeft()
  25. {
  26. rb.velocity = new Vector2(-playerSpeed, 0);
  27. }
  28.  
  29. public void MoveRight()
  30. {
  31. rb.velocity = new Vector2(playerSpeed, 0);
  32. }
  33.  
  34. public void SetVelocityZero()
  35. {
  36. rb.velocity = Vector2.zero;
  37. }
  38. }
Add Comment
Please, Sign In to add comment