I only tried the last one to set it to the TOP parent’s rotation. Didn’t work! The rotation at best only keeps to the first parent’s rotation. This prefab is a child of a child of a so and so forth.
First of all, transform.rotation refers to World space, while transform.localRotation refers to local space. The values you see in the Inspector are always local space, but just because they are zero doesn’t mean the object has no rotation, because one of the parents might.
Secondly, localRotation, as the name suggests, only refers to the LOCAL rotation, that is, the rotation relative to its DIRECT PARENT. This is the reason your last method did what you explained it did, and not what you intended to do.
Most importantly, however, any variant of “rotation” always refers to the Quaternion. You cannot set/access individual angles with these, without calling additional conversion methods. Instead, when dealing with angles, use tranform.eulerAngles and transform.localEulerAngles.
You should be able to figure out the correct settings from the explanations above.
so if you have Box A as a child of Box B, and you rotate Box B,you want Box A to stay still on the X axis?
I would have guessed that transform.rotation.x would have worked as long as it is in an update function but if not you might be able to chat it.
What if you have a empty game object outside with the desired X rotation and you tell Box A,
transform.rotation.x = EmptyGameObject.transform.rotation.x;
That seams very unnecessary, I think we are just missing some Space.World parameter but when I get a chance to test it I will check it out.