2d Object relative rotation with mouse drag.

Hi guys. First of all sorry for my worse English.

I try to make rotate a sprite with mouse drag. I can do it. The script is at below. But the problem is when mouse button down the sprite rotates immediately to the mouse position. I want a rotation with relative to mouse position. I dont want to chase mouse position.

Thanks a lot.

private void Update()
    {
    
  
       
        pos = Camera.main.WorldToScreenPoint(transform.position);

        dir = Input.mousePosition - pos;
        angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        if (Input.GetMouseButton(0))
        {
           
           

               transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

           

        }

      
    }

You would store the position of the mouse when it is first pressed and then calculate the rotation based on how much it has moved while the button is held.

I cant do it :frowning:

What have you tried?