Object Does Not Rotate Correctly

Hey all,

I have the following code in my script:

if(turn == 1 && transform.rotation.y < 30){ 

transform.Rotate (Vector3.up * 1);
print (transform.rotation.y); 

The goal is to have the object rotate when the turn variable is 1 (no problem) and when the object’s rotation is less than 30 degrees. When I run the code above, the console prints out rotation values of 0-1 (unexpected) while Inspector shows values ranging from 0-360 (expected). Since somehow the transform.rotation code thinks that the rotation is different than it really is, the above does not work as expected.

Is there an explanation as to why transform.rotation.y would give another value than Inspector?

I did test this with a basic cube to see if the issue was related to my model or its components. The issue persists.


Unity stores rotations as Quaternions. The angle shown in the editor is just for ease of use, as far as I know. If you want to rotate by a euler angle like that, use a rotation equal to Quaternion.Euler as seen in this example.