In the editor it is easy to reset a child object's transform so that it matches the parent's but is there an easy way to do this in code? I am using the long way:
Is there a shorter (one line) way?
asked Jan 28 '11 at 08:50 AM
Another little improvement ;)
both Transform.rotation and Transform.position are special properties that automatically convert the world position into local position. That's why it's better to set the local position or rotation at least in such a case.
There is no way to set the global scale. Unity just offers a readonly lossyScale to get the resulting scale in world space. (Setting the scale in world space would be a pain to transform the scale through all parents (rotation, position, scale) and would be prone to fail due to inaccuracy of floating point values
answered Jan 28 '11 at 12:02 PM
No, I think your 3 line-way is already pretty much the best you can do. I could think of one potential little improvement:
As Vector3 is a struct this probably won't really make much of a difference as structs are by value and not by reference (if it was a by-reference type this would spare you two objects which later might have to be garbage collected). Nevertheless, I think it's good programming practice to use such "standard objects" for "standard cases".
answered Jan 28 '11 at 09:35 AM