I have a 2D image that I’m trying to rotate to line up over a selected button. I’m using Quaternions, but despite only changing the Z value, it’s rotating the image’s Y value by -90 degrees and screwing it up for reasons I can’t figure out.
public RectTransform pic
//Rotate the image over time to be on the selected button
IEnumerator RotatePic(int selected)
{
float moveSpeed = 0.1f;
float dest = 0;
//Set the right angle for the right button
switch (selected)
{
case 0:
dest = 55;
break;
case 1:
dest = 30;
break;
case 3:
dest = 10;
break;
case 4:
dest = -10;
break;
case 5:
dest = -30;
break;
}
while (pic.rotation.z < dest)
{
pic.rotation = Quaternion.Slerp(pic.rotation, Quaternion.Euler(0, 0, dest), moveSpeed * Time.time);
yield return null;
}
}