Click mesh to trigger action

Hi! My first question:

I have a mesh object and I’d like to trigger a certain action when I click on it with a mouse. It is not a gui object, but a regular 3d object. What do I have to do?

I wrote this script and attached it to the object I want to be clickable, but the event doesn’t execute:

function OnMouseDown() {
	var lid = GameObject.Find("Lid");
	lid.hingeJoint.useLimits = false;
}

Thanks.

  1. Add a print statement so you know when it actually executes

  2. For a 3d mesh to receive the event it needs a mesh collider. Just use the menu Component → Physics → Mesh Collider

  1. I have, it doesn’t execute.

  2. I have the meshcollider attached. I have also tried ticking “is trigger” as I think this should be set?

btw, I am getting a “Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor’s mesh shapes! Please change mesh geometry or supply a tensor manually!” error. Still this doesn’t affect my problem, but I would still love to know what I am doing wrong.

I may be remembering this wrong, but I think I got this error with an old version of Unity when I tried to import a totally flat 2D object I’d created in Blender. Adding a little depth to the object would probably have fixed it, although I think I ended up removing that model entirely in the end.

In fact the model was created in blender… but I’ve spent so much time making it that I don’t really want to remove it…

If you set the collider to be a trigger you will not get mouse down events.

Hm, I’ve tried it both ways, trigger or not it doesn’t execute. I think I’ll just set up the scene from scratch, maybe it will help. Thanks for now.