# Unity3D Get object size in order to be used in Vector3 coordinates

I have a plane in Unity in 3D project, and I want to get its boundaries so I can use them in random function for getting Vector3 coordinates. Currently I am trying like this

GameObject ground;

void Start () {
ground = GameObject.Find("Ground");
moveAreaX = ground.GetComponent<Renderer>().bounds.size.x;
moveAreaZ = ground.GetComponent<Renderer>().bounds.size.z;
Debug.Log ("X Area: " + moveAreaX + ", Z Area: " + moveAreaZ);
GetRandomTargetCoords();
}

void GetRandomTargetCoords() {
targetCoordsX = Random.Range(0f, moveAreaX);
targetCoordsZ = Random.Range(0f, moveAreaZ);
targetCoords = new Vector3(targetCoordsX, 1.1f, targetCoordsZ);

}


And in the console I am getting this:

X Area: 108.5801, Z Area: 108.5801


The problem is the units provided by this bounds.size are not equal to the game object's Transform position's units, and so the game object gets out of the Plane's boundaries.

How can I make it have the same units for measurements?

• Why are you comparing size with position? – Adrian Krupa Jul 14 '15 at 22:32
• dont know, thats exactly what I am trying to figure out, a way to get the plane's coordinates based on its size – Borislav Jul 15 '15 at 6:15

float scale = 0.1f;