x


OnMouseDown() not called on child object collider

I have 27 sub-cubes arranged into a larger cube. I have a box collider for each sub-cube so I can get the OnMouseDown() call in a script for each to change the cube color. But I also have a script to spin the larger cube and added a box collider for it as well, which surrounds all the other colliders of course.

So now it seems I can spin the large cube, but no longer can access the OnMouseDown() functions in the sub-cubes. I tried using a RayCastAll to "penetrate" the large outer box collider to "select" a subcube, but don't get any hits.

What's the right method to do this? It must be possible... THX.

more ▼

asked Dec 29 '10 at 06:21 AM

dweeda gravatar image

dweeda
46 3 4 6

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I was experiencing the same problem, if you have a RigidBody attached to the parent then you may be experiencing this:

By design, compound colliders act as a single collider when you add a rigidbody to the parent, and therefore only the root object will react to OnMouseEnter.

Taken from Eric5h5's comment in: http://answers.unity3d.com/questions/32078/onmouseexit-fires-every-frame-when-the-mouse-is-down

Hope this helps.

more ▼

answered Dec 29 '10 at 08:21 AM

_Petroz gravatar image

_Petroz
3.5k 27 34 57

(comments are locked)
10|3000 characters needed characters left

You should definitely get some hits with RaycastAll.

Keep in mind that your hits will be in an array. You have to loop through the array and do stuff to your sub-cubes. Do your sub-cubes and large cube have different tags? Maybe change their color depending on their tag when you have them as a result of your RaycastAll. In principle, the RaycastAll should work.

more ▼

answered Dec 29 '10 at 07:49 AM

Sebas gravatar image

Sebas
4k 12 18 45

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1682
x407
x119
x21

asked: Dec 29 '10 at 06:21 AM

Seen: 2047 times

Last Updated: Dec 29 '10 at 06:21 AM