i want to figure out how to draw the bounding box of the mesh or collider that is attached to the mesh.
i dont know what to use, bounding box of the mesh, collider or renderer? my goal is to get the position of all
vertices making the bounding box and then render the lines between so that i can get wireframe cube, this way
it will be easy to determine what object is selected in the scene.
is there a easy way to do this? and how to get the vertices. i can get the center of the bounding box like this:
I do something like this in a script attached to the GameObject. It allows me to use the in scene Gizmo’s toggle, as well as my own selection options (like mouse click). (This only applies in the unity Game and Scene windows FYI.)
public bool _bIsSelected = true;
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(transform.position, 0.1f); //center sphere
if (transform.renderer != null)
Here’s my version, which ensures all (self and) child meshes have their bounds drawn and the full object/sub-object transform is used to draw each bounding box.
Gizmos.color = Color.magenta;
foreach(var mf in GetComponentsInChildren<MeshFilter>())
Gizmos.matrix = mf.transform.localToWorldMatrix;
Mesh m = mf.sharedMesh;
Gizmos.DrawWireCube( m.bounds.center, m.bounds.size );