Assigning Parents position and rotation to Variable

Hey All,

How can I assign a parents position and rotation to a variable?

Thanks,
Fenlig

The object “transform” returns the object the script is asigned to. So if you have an object, a box for instance called Mybox, and you assing a script to it (by dragging the script into the box in the editor, for instance) and finally you type this in the script:

Transform varpos;
varpos=transform;

now varpos has position, rotation and scale of the parent of the script (Mybox).

If you have another object MyBoxParent which is the parent of MyBox normally parent and children transform (position, rotation and scale) will be the same, because when you modify parent’s transform you modify automatically children’s transform. But if you want to assign it to a variable anyway, you can use:

Transform varpos;
varpos = transform.parent;