Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Click mesh to trigger action

Discussion in 'Editor & General Support' started by Rhuantavan, Apr 28, 2006.

  1. Rhuantavan

    Rhuantavan

    Joined:
    Feb 23, 2006
    Posts:
    53
    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:

    Code (csharp):
    1.  
    2. function OnMouseDown() {
    3.     var lid = GameObject.Find("Lid");
    4.     lid.hingeJoint.useLimits = false;
    5. }
    6.  
    Thanks.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    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
     
  3. Rhuantavan

    Rhuantavan

    Joined:
    Feb 23, 2006
    Posts:
    53
    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.
     
  4. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    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.
     
  5. Rhuantavan

    Rhuantavan

    Joined:
    Feb 23, 2006
    Posts:
    53
    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...
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    If you set the collider to be a trigger you will not get mouse down events.
     
  7. Rhuantavan

    Rhuantavan

    Joined:
    Feb 23, 2006
    Posts:
    53
    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.