Unity Community


Results 1 to 7 of 7

  1. Location
    Rence, Slovenia, EU
    Posts
    53

    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:

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

    Thanks.
    Damjan "Rhuantavan" Mozetic
    http://damjanmozetic.si


  2. Location
    Unity Technologies HQ, Copenhagen
    Posts
    3,514
    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
    Joachim Ante


  3. Location
    Rence, Slovenia, EU
    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.
    Damjan "Rhuantavan" Mozetic
    http://damjanmozetic.si


  4. Location
    PA, US
    Posts
    366
    Quote Originally Posted by Rhuantavan
    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.


  5. Location
    Rence, Slovenia, EU
    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...
    Damjan "Rhuantavan" Mozetic
    http://damjanmozetic.si


  6. Location
    Unity Technologies HQ, Copenhagen
    Posts
    3,514
    If you set the collider to be a trigger you will not get mouse down events.
    Joachim Ante


  7. Location
    Rence, Slovenia, EU
    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.
    Damjan "Rhuantavan" Mozetic
    http://damjanmozetic.si

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •