title: How do I drag objects on the screen using `OnMouseDrag`?
body: <p>Tried doing 2D and 3D. I want the player to click and drag objects to stack them. I tried copying and pasting code from a video and it still didn't work.</p>
  
  <p>UPDATE! Now it kinda works but it teleports the object far off the screen. I want the player to be able to smoothly click and drag the object.</p>
  
  <p>The code as of now:</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class DragObject : MonoBehaviour
  {
      private float deltax, deltay;
  
  
      private void OnMouseDown()
      {
          deltax = 1f;//Camera.main.ScreenToWorldPoint(Input.mousePosition).x - transform.position.x;
          deltay = 1f; //Camera.main.ScreenToWorldPoint(Input.mousePosition).y - transform.position.y;
      }
  
      private void OnMouseDrag()
      {
          Vector2 currentTouchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
          transform.position = new Vector2((Input.mousePosition).x - deltax, (Input.mousePosition.y) - deltay);
      }
  }
  </code></pre>