I’ve been developing a game in Unity for almost 3 years and I’m still trying to understand how to deal with rotations. One very specific situation is breaking my code and I need help on how to fix that. Here’s my case scenario:
I have an object which can be rotated to absolute values (0 - 90 - 180 - 270), and I need to check that initial rotation before applying some other transformations. I do this:
int angleZ = (int) m_spriteTransform.rotation.eulerAngles.z;
if(angleZ == 270)
Do some stuff;
else if(angleZ > 180 && angleZ < 270)
Do other stuff;
I need to do that check for reasons that are not important now, but here’s what happens. I’m forcing its rotation to be 270 degrees
int angleX = 0;
int angleY = 0;
int angleZ = 270;
m_spriteTransform.rotation = Quaternion.EulerAngles(angleX, angleY, angleZ);
And there is NOTHING at all changing that object’s rotation. Anything. However, when I do the first check, the code if(angleZ == 270)
returns FALSE, and the code else if(angleZ > 180 && angleZ < 270)
returns TRUE, which makes no goddam sense.
I’m setting breakpoints and also a Debug.Log info log and, after checking both, angleZ returns 270, so I don’t know what is happenning.
How can I deal with this properly?