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?

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