Skip to content

Instantly share code, notes, and snippets.

@mminer
Created July 29, 2021 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mminer/4c14af8017150365c9ea44011b7dd0d3 to your computer and use it in GitHub Desktop.
Save mminer/4c14af8017150365c9ea44011b7dd0d3 to your computer and use it in GitHub Desktop.
Unity GameObject extension to calculate its bounds.
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