OnMouseDown() with a Mesh Collider?


I'm working on a project that has house models, which are comprised of multiple meshes, each with their own mesh colliders and mesh renderers.

I have a script (that is confirmed working on anything with a Box Collider) that I want to apply to just a single mesh (outside lamps) of the house.

The script has an OnMouseDown() function, which is crucial. It won't work when applied to the mesh objects, but will work if I custom-fit a Box Collider over the object. This is a pain though, and won't work if the parts of the model aren't contiguous.

Is there a simple solution to this? Am I being stupid? Any help would be appreciated!

Thanks, SpoonyBard

EDIT: Turns out it might not be related to Mesh Colliders, as a Cube with a Mesh Collider works fine. Is there a setting to do with the model itself that I might be forgetting? The house and all of its parts seem to collide fine!

When this sort of thing happens with us, it is typically because the collision mesh doesn't match up to the visual mesh. The most common causes: a rotation of one that is not applied to the other, or a scaling difference. Selecting the object in the hierarchy should highlight the collision in light green for a visual check.

Sorry if this is obvious, but it happens to us enough that I figured it was worth mentioning.

The problem is that if you have a complex conglomeration of several meshes, when you click on one, it does do an OnMouseDown event... but it does not send that event upwards. So if you have a house composed of several meshes, then clicking on it is working as intended... but the top level parent is not receiving the click events.

A couple ways to solve this:

Make a simple script with a variable for the parent, then place the script on each child mesh. This script will simply have an OnMouseDown event that will find the key script on the parent, and call the relevant functions there.

Put the key script on every child mesh(not recommended for bigger meshes).