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.