- Home /
Getting bounds of submeshes
Hey all,
I have a game object that has multiple game object children which are loaded dynamically. All the children have meshes and the main game object doesn't. The main game object does have a box collider which the children have not. So what I would like to do now is set the bounds of that boxcollider of the parent to fit the childmeshes. Does anyone know how to do this?
Answer by MikeNewall · Jan 29, 2014 at 03:02 PM
Use the Bounds.Encapsulate method to encapsulate the bounds of each child mesh. Something like this;
     foreach (var meshFilter in transform.GetComponentsInChildren<MeshFilter>()) {
         collider.bounds.Encapsulate(meshFilter.mesh.bounds);
     }
http://docs.unity3d.com/Documentation/ScriptReference/Bounds.Encapsulate.html
Your answer
 
 
             Follow this Question
Related Questions
mesh colliders moving when i press play 1 Answer
how do i make my modle solid? 2 Answers
adding mesh collider in run time slow? 3 Answers
Edit WheelCollider's Axis, not the Mesh 0 Answers
How to rotate a mesh collider? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                