i want to render boundingbox of the collider and i know about properties of bounds like size,extents and center but i dont know how to get 8 vertices that make bounding box.

any help here from somebody experienced?

Hi,

I know this topic is pretty old but here is my take on how to get the 8 points of a bounding cube : just use the Bounds.min and Bounds.max variables to get the two extreme points, then alternate between min.x/y/z and max.x/y/z to construct the 6 other Vector3.

	boundPoint1 = collider.bounds.min;
	boundPoint2 = collider.bounds.max;
	boundPoint3 = Vector3(boundPoint1.x, boundPoint1.y, boundPoint2.z);
	boundPoint4 = Vector3(boundPoint1.x, boundPoint2.y, boundPoint1.z);
	boundPoint5 = Vector3(boundPoint2.x, boundPoint1.y, boundPoint1.z);
	boundPoint6 = Vector3(boundPoint1.x, boundPoint2.y, boundPoint2.z);
	boundPoint7 = Vector3(boundPoint2.x, boundPoint1.y, boundPoint2.z);
	boundPoint8 = Vector3(boundPoint2.x, boundPoint2.y, boundPoint1.z);

Easy, quite typo-free.

First I'll answer the question, then I'll mention two alternatives that don't involve computing the 8 vertices.

1) The extents (x, y, and z) are half of the size in those directions. So you can get one corner by subtracting the extents from the center, and the opposite corner by adding the extents:

Vector pt1 =  collider.bounds.center - collider.bound.extents;
Vector pt2 =  collider.bounds.center + collider.bound.extents;

The other corners can be found by adding some extents, subtracting others. Something like:

Vector pt3 = New Vector3(collider.bounds.x - collider.bound.extents.x, 
                         collider.bounds.y + collider.bound.extents.y, 
                         collider.bounds.z + collider.bound.extents.z); 

This time I subtracted x, added y, added z. There are 8 possible combinations of additions and subtractions. Those are your 8 vertices.

2) But maybe you don't need the 8 vertices. You could instead create a GameObject that's a 1x1x1 cube, then move it to the center of the collision, and set the scale of the cube to match the size of the collider. I didn't test this, but it would look something like this:

GameObject myCube = GameObject.CreatePrimitive(PrimitiveType.Cube); // or, instantiate a prefab cube
myCube.tranform.position = collider.bounds.center;
myCube.tranform.localScale = collider.bounds.size;

(And instead of creating a primitive cube, you could instantiate a prefab cube, which would have whatever material, scripts, and other components you wanted to put on it.)

3) If you just want to draw it in the Scene View for debugging purposes, you can simply call Gizmos.DrawCube or Gizmos.DrawWireCube, passing it bounds.center and bounds.size as the arguments.

// if you want make a cube mesh

           var boundsMesh = go.AddComponent<MeshFilter>();
	boundsMesh.mesh = new Mesh();
		boundsMesh.mesh.vertices = new [] { boundPoint1, boundPoint2, boundPoint3, boundPoint4, boundPoint5, boundPoint6, boundPoint7, boundPoint8 };
		boundsMesh.mesh.triangles = new[]
		{
			0,7,4,
			0,3,7,
			5,1,3,
			3,1,7,
			7,1,4,
			4,1,6,
			5,3,2,
			2,3,0,
			0,4,2,
			2,4,6,
			1,5,2,
			6,1,2
		};