Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

MouseOver not activating script? What am I missing?

Discussion in 'Scripting' started by Palimon, Aug 18, 2014.

?

Have you also had problems with MouseOver/MouseClick when learning Unity?

  1. Having this problem now.

    33.3%
  2. Had it when I started Unity, but no longer.

    33.3%
  3. Nope.

    33.3%
  1. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Hey all, I'm pretty new to Unity and having a terribly time getting mouseover and mouseclicking actions to work. Can you please tell me what I'm doing wrong and/or missing? In the picture I show my game object with script and collider, and my script code in MonoDev. I've had this working perfectly before (hence all the commented out code), but it stopped working and I can't get it working again, so there's something I'm not understanding. Specifically right now, it's not entering the OnMouseEnter method when I mouseover the object in-game. I've dug through tons of previous forum threads on this topic, which are many, and nothing's helped yet. Help please! :)

     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you're collider isn't the same size/shape as your mesh renderer. It'll only work over the collider.

    also, why the poll??
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
    in Physics settings page there is [x] Raycast hits trigger.. is that enabled?
     
  4. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    @LeftyRighty
    Can you expand on "It'll only work over the collider" please? My understanding is the collider works completely seperate from the mesh, in that I can maybe even have a collider without a mesh. I increased the collider size in the hopes that maybe it was just inside the mesh and wasn't being hit by a raycast. The poll is because I'm curious :p

    @mgear
    Yes, that is enabled.
     
  5. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    Yes colliders work seperate it wont matter if its bigger or smaller then the mesh but try disabling isTrigger i cant remeber at this moment it think that might be it though
     
  6. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    Update: Trigger or no trigger doesnt seem to affect it
     
  7. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Yeah, isTrigger either way doesn't show any effect. I even tried pulling my camera far outside of my character capsule to make sure it wasn't hitting that, but nope. Let me know if there's any other info of my project I can upload for you guys that might help you diagnose.
     
  8. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    Make sure that the game scene is ACTIVE that the last place you clicked is the game scene
     
  9. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Yep, it is. I've clicked a lot in there.
     
  10. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Another note: if I add a RigidBody component to my sphere, my mouseover script works perfectly. Absolutely perfect. Without it, it doesn't work at all. Could this be a bug introduced in the latest build or something? Everything I know about these components, which granted isn't much, points to this being a very odd behavior.
     
  11. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    try to remove the Controllbutton component and add it back i dont think it matters but it mighht be the order
    No its not a bug in the latest version since it works for me and i got the latest but when you say it i think it was a bug in a earlier version
     
  12. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Tried adding the ControlButton and Script components in any order to no effect. Also updated to the latest version, and I'm still seeing the same problem - I probably should have thought of that before though :p.
     
  13. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    yeah well i didnt think it would matter as it didnt at my test there must be something obstructing it
     
  14. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    There can't be anything obstructing it - if I add the RigidBody component, it floats away because it starts in contact with the pillar below, but if I mouse over it, my OnMouseEnter debug statement pops up, and same with the OnMouseUpAsButton if I click. It works perfectly every time...but only if I have a RigidBody on it.
     
  15. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    then have rigidbodies on them and jsut set them as IsKinematic
     
  16. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    I've thought about that, but I don't yet understand what all the results of marking something IsKinematic is yet. The documentation says it doesn't respond to physics. Can they still collide with other objects, but just don't move themselves?

    Edit: Just found a more detailed description in the API: http://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html
     
  17. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Ok, while that works for testing purposes now, that's not going to work long-term. I tried something out for kicks, and moved the Control Console object to the top of the hierarchy instead of underneath Spaceship 1. It works perfectly. Maybe I don't understand the Unity hierarchy very well, but how would being a child of something else stop a collider from working? Maybe a child must be a RigidBody if the parent is? Spaceship 1 is a RigidBody.
     
    Last edited: Aug 20, 2014