hi just try calcul box size for set the boxcollider on all in children
got somehtink’s like this
public void calcul_size(){
GameObject[] obj = Selection.gameObjects;
List<MeshFilter> objlist = new List<MeshFilter> ();
Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
if (obj [0].GetComponent<MeshFilter> () != null)
objlist.Add (obj [0].GetComponent<MeshFilter> ());
for (int i = 0; i < obj[0].transform.childCount; i++) {
if (obj[0].transform.GetChild(i).GetComponent<MeshFilter> () != null)
objlist.Add (obj[0].transform.GetChild(i).GetComponent<MeshFilter> ());
}
Vector3 vv = Vector3.zero;
Vector3 centroid = new Vector3(0,0,0);
foreach (MeshFilter item in objlist) {
bounds.Encapsulate( item.sharedMesh.bounds);
bounds.center = Vector3.zero;
centroid += item.sharedMesh.bounds.center;
}
centroid /= ( objlist.Count+1 );
bounds.center = centroid;
BoxCollider collider = obj [0].AddComponent<BoxCollider> ();
collider.size = bounds.size;
}