Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Extrakun · Jun 10, 2010 at 12:06 PM · rendering

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Eric5h5 · Jun 11, 2010 at 08:14 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Extrakun · Jun 11, 2010 at 09:47 AM 0
Share

Vectrosity looks great!

avatar image
3

Answer by newbrand · Jun 10, 2010 at 02:32 PM

(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:

  • http://unity3d.com/support/documentation/ScriptReference/Mesh-bounds.html and
  • http://unity3d.com/support/documentation/ScriptReference/Camera.WorldToScreenPoint.html

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?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Extrakun · Jun 11, 2010 at 03:47 AM 0
Share

Thanks, what if I want a 3D bounding box>

avatar image
0

Answer by tomekkie2 · Jul 06, 2011 at 02:04 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Modifying PlayerSettings for RenderPath 1 Answer

Camera Meshrenderer in a multiplayer game 2 Answers

Gun clipping through walls in third person shooter 1 Answer

using camera.Render() to render to a RenderTexture is not depth testing? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges