title: Unity hold touch move horizontally
body: <p>I have no idea how to start this, I want to move my character left and right when holding the touch.</p>
  
  <p>Like in this game:</p>
  
  <p><a href="https://i.stack.imgur.com/rNBDK.png" rel="nofollow noreferrer">Example Game - Stairs from Ketchapp</a></p>
  
  <p><img src="https://i.stack.imgur.com/rNBDK.png" alt=""></p>
  
  <p>I have only my script that detects the left or right space of the screen.</p>
  
  <pre><code>public float forwardSpeed = 5f;
  public float sideSpeed = 5f;
  
  private void Update()
  {
      Vector3 deltaPosition = transform.forward * forwardSpeed;
      if (Input.touchCount &gt; 0)
      {
          Vector3 touchPosition = Input.GetTouch(0).position;
          if (touchPosition.x &gt; Screen.width * 0.5f)
              deltaPosition += transform.right * sideSpeed;
          else
              deltaPosition -= transform.right * sideSpeed;
      }
      transform.position += deltaPosition * Time.deltaTime;
  }
  </code></pre>