Draw the bounding box for a selected game object, outside of editor?

The idea here is to draw a bounding box to indicate to the user that a game-object is selected. How can I do this outside of Editor mode (say published player)?

Note: What if I wish the bounding box to be rendered within its 3d space

If by "3D bounding box" you mean something like a cube, then do this: Instantiate a cube with a partially-transparent material, give it the same position and rotation of the object, then use the object's mesh.bounds to scale the cube to the correct size.

If you're talking about wireframes, then yeah, you can certainly make 3D wireframe bounding boxes with Vectrosity. Unfortunately wireframe line drawing is normally not that simple to do in Unity outside the editor, which is why I made this utility, in order to fix that problem.

(Assuming that you mean a bounding box as in most rts-games and not a 3d bounding box:)

I'm treading on very thin ice here because I never tinkered with bounds, so I can only guess how I would do it if I had to. Sorry if I state the obvious.

  1. The bounds of your mesh are stored in mesh.bounds: Bounds.
  2. Use Camera.WorldToScreenPoint to translate the min and max values of bounds to screen coordinates.
  3. Draw your box in OnGUI (just drawing the edges would probably be easier)
  4. Alternatively you could probably also instantiate a plane/cube with the proper texture applied and align/resize it to fit.

See also:

Answering your comment: See #4. If you use a transparent material with a border-texture it shouldn't look too bad as long as the box is not stretched too much. Alternatively, take a look at Eric5h5's Vectrosity if you have a few bucks to spend: http://forum.unity3d.com/viewtopic.php?t=53268

Meta: Seriously, why can't I post comments? I got enough of this stupid rep according to the faq, so what's the big deal?

I have developed my own solution for a runtime wireframe bounding box. I have based it on the mesh.renderer.bounds or alternatively collider, dealt with a script attached to object. The box itself is being drawn by another script attached to camera and using GL.LINES. You can see in working on my blog page http://virtualplayground.d2.pl and can download these scripts from there.