I'm working in this Robot-Toy, I am trying to fix the rotation of the arm, but the Arm rotates keeping the same orientation don't change (always see to the same direction).
(The Base's Arm (in color green) rotates well, but the Arm as a "children" rotates keeping the same orientation)
Please take a look to the image.
Here it is the Script I am using for the base in green color.
And here it is the script for the arm " who has to rotate according to the arm but it doesn't (It rotates but always keeping the same orientation)
Any advice is welcome.
Your code should rotate the whole hierarchy. It sounds to me that your children have some code affecting their world rotation somehow. Are there other scripts involved?
In your updated code you set rotation this way:
This sets the world rotation (absolute rotation) of the object. You likely want to set the local rotation, so hierarchy rotations are preserved. This is done simply.
Likewise, you should store the localRotation in your Start function.