title: Moving an object quickly accros the screen using touch in Unity?
body: <p>I'm currently developing a game and I want to allow the player to drag a gameobject across the screen using touch controls. However, for some reason, my code keeps on returning an error('deltaPosition' does not exist in the current context), which shouldn't happen because I got the code from a youtube video where it didn't display any compiling errors when the person showed the code. Is this due to a new version of C# or does someone know how I could solve this problem. Thanks<a href="https://i.stack.imgur.com/8kTgM.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  
      public class PositionTracker : MonoBehaviour
      {
          [SerializeField]
          float                  _horizontalimit = 2.5f, _verticalLimit = 2.5f, dragSpeed = 0.1f;
  
          Transform cashedTransform;
  
          Vector3 startingPos;
  
  
          void Start()
          {
              cashedTransform = transform;
              startingPos = cashedTransform.position;
          }
  
          void Update()
          {
              if (Input.touchCount &gt; 0)
              {
                  Vector2 deltaPostion = Input.GetTouch(0).deltaPosition;
  
                  switch (Input.GetTouch(0).phase)
                  {
                      case TouchPhase.Began:
                      break;
  
                      case TouchPhase.Moved:
                          DragObject(deltaPosition);
                          break;
  
                      case TouchPhase.Ended:
                          break;
                  }
              }
  
              //Debug.Log("target is " + touch.position + " pixels from the left");
          }
  
          void DragObject(Vector2 deltaPostion)
          {
              cashedTransform.position = new Vector3(Mathf.Clamp((deltaPosition.x * dragSpeed) + cashedTransform.position.x,
                  startingPos.x - _horizontalimit, startingPos.x + _horizontalimit), 
              Mathf.Clamp((deltaPostion.y * dragSpeed) + cashedTransform.position.y,
              startingPos.y - _verticalLimit, startingPos.y + _verticalLimit),
              cashedTransform.position.z);
  
          }
      }
  </code></pre>