Created
July 29, 2021 22:08
-
-
Save mminer/4c14af8017150365c9ea44011b7dd0d3 to your computer and use it in GitHub Desktop.
Unity GameObject extension to calculate its bounds.
This file contains hidden or 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
public static Bounds GetBounds(this GameObject gameObject) | |
{ | |
var bounds = new Bounds(gameObject.transform.position, Vector3.zero); | |
var renderers = gameObject.GetComponentsInChildren<Renderer>(); | |
foreach (var renderer in renderers) | |
{ | |
bounds.Encapsulate(renderer.bounds); | |
} | |
return bounds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment