• 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
0
Question by MigLeader · Jul 25, 2012 at 07:10 AM · meshobjectsboundsmeshfilterhighlight

Getting Bounding box from a collider with children

hi there my friends , ok here is my problem: i have an empty game object and it have a lot of child objects (its a room) i want when i hover my mouse at it , it gets highlighted by the bounding box of the room , the problem is the empty game object does not have a renderer or anything else , only a collider its like this:

MeeteingRoom (empty game object that have only a box collider)
otherobjects (the models themselfs)
.....
.....
.....

the code for mouse hover is done and working fine , but how i could highlight the whole object is still not working , i was thinking of using mesh.bounds but the empty game object dont have a mesh (it must not have mesh).

on the other hand , i tried the following code:

 var roomObjects : GameObject;
 var highlightmat : Material;
 var selectedObject : GameObject;
 
 function Update(){
  var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  var hit : RaycastHit;
  if (Physics.Raycast (ray, hit, 500)) {
  Debug.DrawLine (ray.origin, hit.point);
  if(hit.collider.tag == ("Rooms")){
  Debug.Log(hit.collider.gameObject);
  selectedObject = hit.transform.gameObject;
  //isHighlighted();
  }else{
  Debug.Log("Notting!!");
  selectedObject = null;
  //NotHighlighted();
  }
  }
 }
 
 function isHighlighted(){
 
 }
 
 function NotHighlighted(){
  
 }
 
 function OnPostRender()
 {
  if( selectedObject == null )
  return;
  
  var go = selectedObject;
  highlightmat.SetPass( 0 );
  var meshes = go.GetComponentsInChildren(MeshFilter);
  for( var m : MeshFilter in meshes )
  {
  Graphics.DrawMeshNow( m.sharedMesh, m.transform.position, m.transform.rotation );
  }
 }


it works great but the scale is wrong bcz the importer scales the imported objects from 1.0 to 2.54 , how can i take the scale and add it to the above script?

thanks for any help i get.

Comment
Add comment · Show 2
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 whydoidoit · Jul 25, 2012 at 07:29 AM 1
Share

Colliders have bounds too - is that not what you need?

avatar image MigLeader · Jul 25, 2012 at 08:39 AM 0
Share

i tried using it but didnt get it right , i have read the docs about bounds , but still i cant get it right , can u post just an example on how to use it probably.

thx for ur time

1 Reply

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

Answer by ScroodgeM · Jul 25, 2012 at 09:15 AM

solution 1

make a raycast from mouse, take returned by hit collider, then an object of this collider, then root of this object. if this object is your room - make a highlight recursively to childs

solution 2

make a script with OnMouseOver method for each child and on mouse over event turn on highlight

solution 3

create a one big collider that covers whole room and attach it ro empty gameobject. then use simple OnMOuseOver from previous solution
Comment
Add comment · Show 3 · 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 MigLeader · Jul 25, 2012 at 01:36 PM 0
Share

thanks my good sir for ur help , but i have the script for raycasting from a mouse working fine , wt i was asking is how i can make a proper highlighting graphics for the highlighted objects as whole while the collider is only just a big bounding box that have only collider in it.

still thanks a lot for ur time and ur solutions.

avatar image ScroodgeM · Jul 27, 2012 at 09:13 AM 0
Share

if your question is how to access other gameobjects:

you can make a object with a collider as parent for all objects that should be highlighted, and then just recursively take them all (for each (Transform child in transform) {})

if your question is how to change graphic:

  • you can use a different material with another shader like self-illu$$anonymous$$ated ins$$anonymous$$d of diffuse, and change for all objects material to highlighted one

  • you can use a different shader and change for all objects shader

  • you can use a shader with highlighted mode, for example - self-illu$$anonymous$$ated shader that have illu$$anonymous$$ation color. changing this color from black to some color will cause object to be highlighted

avatar image MigLeader · Jul 27, 2012 at 02:13 PM 0
Share

i was looking for the for accessing other gameobjects , i tried it and it works , thx a lot for ur help.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Bounds of dynamic mesh not updating 1 Answer

Instantiate within boundaries of Mesh shape 2 Answers

Mesh filters missing their meshes when project cloned from bitbucket 2 Answers

Procedural array of meshes problem / solved 1 Answer

Can't change verts on mesh after assigning to meshfilter. 1 Answer


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