Get Bounds from Canvas with Text objects

by tmighty   Last Updated July 11, 2019 20:13 PM - source

To get the bounds of an object that has MeshRenderers, I use the following function:

public static Bounds BoundsFromTransform(Transform uTransform)
    Bounds bounds = new Bounds(uTransform.position,;
    foreach (Renderer renderer in uTransform.GetComponentsInChildren<Renderer>())
    Vector3 nOff = - uTransform.position;
    return new Bounds(nOff, bounds.size);

I would now like to get bounds of an object that contains the following:

1) A canvas / canvas scaler 2) Panel with an image 3) Text 1 4) Text 2 etc.

How could I get the bounds from such an object?

My approach was to use the "ItemmenuCanvas" transform's localScale as I thought this would determine this complex object's scale, but its localScale was too small to feel right.

Here are some screenshots:

enter image description here

enter image description here

enter image description here

Thank you very much!

Tags : unity c#

Related Questions

Unfortunately game has stopped

Updated July 02, 2019 11:13 AM

How to animate objects in Unity 3D

Updated July 12, 2015 13:05 PM