- Home /
True scale of a visible GameObject with many childs
For a GameObject (empty), which contains many children, how do you find the bounds or scale of the "collective visible object" created by the children?
Sorry, not sure how to ask this exactly, but tried both Bounds struct/class and localScale (of course) but neither seem to register the extremes created by the childrens' extent.
Comment
Best Answer
Answer by luizgpa · Jan 22, 2012 at 04:56 PM
I don't know what you mean by "true scale", but if want to know the AABB that encloses all children objects you could create an empty Bounds, go through all the children's Renderers and Encapsulate it's bounds. Eg:
Bounds bounds = new Bounds(transform.position, Vector3.zero);
foreach(Renderer r in GetComponentsInChildren<Renderer>()) {
bounds.Encapsulate(r.bounds);
}
I'm pretty sure the OP was after that, but you can never be sure ;)
+1
How do I use it in a java script? I need the size to be printed in the console for now.