Confusing transform.localRotation issue

Hi.

I’m having a weird issue. Basically, I have a variable named ‘localRotation’, which I set in the inspector. At some event, I parent the object; Right after parenting it, I set the local rotation to ‘localRotation’. Watching the inspector while playing the game, the rotation gets set to a completely different value.

To be exact, the localRotation variable is set to 290.5288, 112.644, 221.3834 (w is 0) and the rotation that gets set is 340.0402, 110.496, 151.5359. I never change the rotation of the object or the values of the variable anywhere else.

transform.parent=col.transform;
transform.localPosition=localPosition; //Position gets set correctly
transform.localRotation=localRotation;  //Rotation does not

It would be great of someone could spot the problem.

Thanks in advance!

Rotations are represented as Quaternions. They have nothing to do with angles in degree or radians. You probably want to use localEulerAngles and use a Vector3 as your public variable. The localEulerAngles is what you see in the inspector.