transform.rotation.x not reporting correctly

if i debug.log(transform.rotation.x); it will give me some random value

if i lock the rotation in all directions, it will still be able to rotate

if i look in the editor, the X value of the rotation is correct, the debug.log is wrong.

i need to use the X value of the rotation. it will not let me no matter what.

“if i look in the editor, the X value of the rotation is correct, the debug.log is wrong.”

There is no “correct” value for a 3D rotation. Period.

There might be a value that you want to see there but this is not how it works. The crucial thing you have to understand about rotations is that Unitys basic structure to hold rotations is in Quaternions. This has a good reason as only a quaternion is unique to one rotation. As soon as you enter the realm of euler angles there are always multiple ways to describe the same 3D-rotation with different sets of euler angles.

An additional misconception you might eperience here is that debug.log(transform.rotation.x); shows the euler angle around the x-Axis in global coordinates. The inspector will always show the local rotation so the values might be different.

A further difference is that the inspector can show angles > 360 or negative values. When you get your euler rotation from debug.log(transform.rotation.x); the value will always be wrapped when leaving the 0 < angle < 360 boundaries.

Then the point about locking the rotation: This implies that you have a rigidbody on your object. This will only lock the rotation to be modified from physical interactions. You can still modify the rotation of an object by directly manipulating the rotation. There is no way to make a rotation truly constant.