Need help converting rectTransform.rotate to slider value

I’m trying to get a slider valued 0-1 to correspond to the rotation of an image. 180 degrees = 0.5, 90 degrees = 0.25, etc.

Here’s what I have now:

void Update()
    {
        Vector3 difference = rotator.transform.InverseTransformPoint(Input.mousePosition);
        var angle = Mathf.Atan2(difference.x, difference.y) * Mathf.Rad2Deg;
        rotator.transform.Rotate(0f, 0f, -angle);

       
        if(rotator.rotation.z < 0) slider.value = (100 + (rotator.rotation.z / 3.6f));
        else slider.value =  (rotator.rotation.z / 3.6f);

        myImage.fillAmount = slider.value;
       
    }

The first 3 lines rotate the rectTransform toward the mouse, the second two set the value of the slider based on the rotation of the rectTransform.

I believe the two equations should work. When doing them by hand 90d = 25, -90d = 75, 1d = 0, -1d = 99. In practice however it works until the slider reaches about 25 percent, then it slows, starts going backwards, and jumps all the way to 100 if I bring it 360d or more. Any help would be greatly appreciated.

Line 4 calculates the polar angle from the x/y pair.

Line 5 says “rotate this transform BY this amount,” not TO this amount. In other words, it is relative to wherever rotator was before this.

Instead, for line 5 you need some variation of:

rotator.transform.localRotation = Quaternion.Euler (0, 0, angle);

ALSO: line 8, you cannot read from that .z. It is NOT the Euler angles. rotation.x,.y,.z and .w are NOT angles.

Instead, use the angle above to drive your slider.