Created
June 25, 2013 04:18
-
-
Save jimfleming/5855904 to your computer and use it in GitHub Desktop.
Sizes a bounding box to its children.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BoxCollider collider = gameObject.AddComponent<BoxCollider>(); | |
Bounds parentBounds = new Bounds(Vector3.zero, Vector3.zero); | |
Bounds childBounds = new Bounds(Vector3.zero, Vector3.zero); | |
MeshFilter[] meshFilters = transform.GetComponentsInChildren<MeshFilter>(); | |
foreach (MeshFilter meshFilter in meshFilters) { | |
childBounds.center = transform.InverseTransformPoint(meshFilter.renderer.bounds.center); | |
childBounds.size = meshFilter.sharedMesh.bounds.size; | |
parentBounds.Encapsulate(temp); | |
} | |
collider.size = bounds.size; | |
collider.center = bounds.center; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment