title: Simulate "Swipe to Unlock" in Unity 3D
body: <p>I have to create a "Swipe to Unlock" feature in Unity 3D ( just like the one in iPhone lock screen). I tried the followings:</p>
  
  <p><strong>Part 1 - Detect Swipe</strong></p>
  
  <p>I'm able to detect a swipe using the following codes:</p>
  
  <pre><code>private bool couldBeSwipe = false;
  private float minSwipeDistance = 14;
  private float maxSwipeTime = 10;
  private float comfortZone = 100;
  private float startTime;
  private Vector2 startPos;
  const int SWIPE_NONE = 0;
  const int SWIPE_UP = 1;
  const int SWIPE_RIGHT = 2;
  const int SWIPE_DOWN = 3;
  const int SWIPE_LEFT = 4;
  private int swipeDirection = SelectStageScene.SWIPE_NONE;
  </code></pre>
  
  <p>In <code>void Update()</code>:</p>
  
  <pre><code>    // Input
      swipeDirection = SelectStageScene.SWIPE_NONE;
      if (Input.touchCount &gt; 0) {
          Touch touch = Input.touches [0];
          switch (touch.phase) {
          case TouchPhase.Began:
              couldBeSwipe = true;
              startPos = touch.position;
              startTime = Time.time;
              break;
          case TouchPhase.Moved:
              if ((Mathf.Abs (touch.position.y - startPos.y) &gt; comfortZone) &amp;&amp; (Mathf.Abs (touch.position.x - startPos.x) &gt; comfortZone)) {
                  couldBeSwipe = false;
              }
              break;
          case TouchPhase.Ended:
              float swipeTime = Time.time - startTime;
              float swipeDistance = (touch.position - startPos).magnitude;
              float deltaX = touch.position.x - startPos.x;
              float deltaY = touch.position.y - startPos.y;
  
              if (couldBeSwipe &amp;&amp; (swipeTime &lt; maxSwipeTime) &amp;&amp; (swipeDistance &gt; minSwipeDistance)) { 
                  if (Mathf.Abs (deltaX) &gt; comfortZone) {
                      float swipeDirectionY = Mathf.Sign(deltaX);
                      if (swipeDirectionY == 1) {
                          swipeDirection = SelectStageScene.SWIPE_RIGHT;
                      } else {
                          swipeDirection = SelectStageScene.SWIPE_LEFT;
                      }
                  }
                  if (Mathf.Abs (deltaY) &gt; comfortZone) {
                        float swipeDirectionY = Mathf.Sign(deltaY);
                        if (swipeDirectionY == 1) {
                              swipeDirection = SelectStageScene.SWIPE_UP;
                    } else {
                              swipeDirection = SelectStageScene.SWIPE_DOWN;
                    }
                  }
              } else if (swipeTime &gt; maxSwipeTime) {
                  Debug.Log ("Too slow");
                  swipeDirection = SelectStageScene.SWIPE_NONE;
              } else if (swipeDistance &lt; minSwipeDistance) {
                  Debug.Log ("Too short");
                  swipeDirection = SelectStageScene.SWIPE_NONE;
              } else if (!couldBeSwipe) {
                  Debug.Log ("Not a swipe");
                  swipeDirection = SelectStageScene.SWIPE_NONE;
              } else {
                  swipeDirection = SelectStageScene.SWIPE_NONE;
              }
              break;
          }
      }
  </code></pre>
  
  <p><strong>Part 2 - Move a Texture (with axis constraint)</strong></p>
  
  <p>There are several ways to move a Texture, including <code>GUI.DragWindow()</code>, <code>GUI.Box()</code>, etc. But none is directly moving a <code>Texture</code>. Which is the simplest way to move a Texture along an axis. For example, constraint its movement only on X-axis ?</p>