Advertisement
mrkiller2010

Unity touch

Jul 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
  2.             {
  3.  
  4.                 float touchDeltaPositionX = Input.GetTouch(0).deltaPosition.x;
  5.                 float position = this.transform.position.x;
  6.                 float touchDeltaPositionY = this.transform.position.y;
  7.  
  8.                 if (position > -4f && position < 4f)
  9.                 {
  10.                     transform.Translate(touchDeltaPositionX * Time.deltaTime * sensitivitySlider.value, touchDeltaPositionY * 0, 0);
  11.                 }
  12.                 else if (position <= -4f)
  13.                 {
  14.                     if (touchDeltaPositionX > 0)
  15.                     {
  16.                         transform.Translate(touchDeltaPositionX * Time.deltaTime * sensitivitySlider.value, touchDeltaPositionY * 0, 0);
  17.                     }
  18.                 }
  19.                 else if (position >= 4f)
  20.                 {
  21.                     if (touchDeltaPositionX < 0)
  22.                     {
  23.                         transform.Translate(touchDeltaPositionX * Time.deltaTime * sensitivitySlider.value, touchDeltaPositionY * 0, 0);
  24.                     }
  25.                 }
  26.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement