Hi there,

I would like to know how to find the size of an object. eg vector3(10.0f,10.0f,10.0f); gameOjbject.size:vector3

What code would I have to use to find the total size of a GameObject? How would I do it.

Thanks

Hi there,

I would like to know how to find the size of an object. eg vector3(10.0f,10.0f,10.0f); gameOjbject.size:vector3

What code would I have to use to find the total size of a GameObject? How would I do it.

Thanks

If the object has a renderer, then renderer.bounds.size will give you what you want

Next best thing would probably be collider.bounds.size

The correct code for recent version of Unity is:

```
GetComponent<Collider>().bounds.size
GetComponent<Renderer>().bounds.size
```

I believe the correct Unity5 code is:

```
GetComponent.<Collider>().bounds.size
GetComponent.<Renderer>().bounds.size
```

The ‘.’ before the requested component is needed.

**transform.bounds** gives you the global size, axis oriented.

if you want the REAL size of the object, ignoring the transformations done to the object, use **mesh.bounds** which gives you the local size of the mesh.

For 2D sprite:

```
var p1 = gameObject.transform.TransformPoint(0, 0, 0);
var p2 = gameObject.transform.TransformPoint(1, 1, 0);
var w = p2.x - p1.x;
var h = p2.y - p1.y;
```

This works whether or not the item is active.