title: Unity3d Move 2D Sprite relative to mouse position
body: <p>if I move my sprite with the mouse, the sprite is always exactly under the cursor.</p>
  
  <p>At the moment my code looks like that:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>    public GameObject player;
      private float distance = 1;
  
      private void Update()
      {
          if (Input.GetMouseButton(0))
          {
              Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
              Vector3 playerPos = Camera.main.ScreenToWorldPoint(mousePos);
              player.transform.position = playerPos;
          }
      }
  </code></pre>
  
  <p>but i want to move the sprite, no matter where my mouse courser is on the background. so if i click and hold next to the sprite and move my mouse to the right, i want that my sprite move the same way in same direction.</p>
  
  <p><a href="https://i.stack.imgur.com/RSLoN.jpg" rel="nofollow noreferrer">Example Picture</a></p>