What could be the reason

Hi friends,

Whenever I rotate an object in Unity the values are different when I print using Debug.Log and in the inspector.

There might be a possibility that in CG, the rotation happens in counter clockwise direction. Means, rotating left actually increases rotation, and towards decreases. The problem comes in decreasing rotation. It doesn’t give negative values.

That is when I rotate towards +ve right direction, it decreases from 360 - the amount of rotation. Giving positive values.

But when I want to limit an angle with limits, this is giving problems. How can solve this? What is exact reason behind this?

Please suggest some ideas.

It’s because you are checking the EulerAngles and not the Quaternion, which the values can be managed by Unity for some reasons explained here : Whats the Difference Between Rotation EulerAngles and Quaternions? - Unity Answers

If you want to check an angle I would suggest to check this with the Vector3.Angle for exemple and check if your object and the direction vector you want are close. You can also look to Quaternion.LookRotation method.