Answers for "unity get gameobject height"

C#
1

unity get gameobject height

// Unity 2D:
float width = GetComponent<SpriteRenderer>().bounds.size.x;

/* Source:
https://answers.unity.com/questions/960170/how-to-find-width-and-height-of-sprite-object-unit.html
*/

/* Unity 3D:
If your object has a renderer, you can use renderer.bounds.size, which
will return a vector with the height and width (and depth, if it is in 3D).
You can also get the width and height from the colliders on a gameObject as 
well, by using collider.bounds.size. Try something like this: */
public Vector3 size;
private MeshRenderer renderer;

private void Start() 
{
    renderer = GetComponent<MeshRenderer>();
    size = renderer.bounds.size;
}


/* Source:
https://stackoverflow.com/questions/54699670/unity-width-and-height-of-the-gameobject/54700269
*/
Posted by: Guest on August-15-2021

Code answers related to "unity get gameobject height"

C# Answers by Framework

Browse Popular Code Answers by Language