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! ![]()
you’re collider isn’t the same size/shape as your mesh renderer. It’ll only work over the collider.
also, why the poll??
in Physics settings page there is [×] Raycast hits trigger… is that enabled?
@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 ![]()
@mgear
Yes, that is enabled.
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
Update: Trigger or no trigger doesnt seem to affect it
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.
Make sure that the game scene is ACTIVE that the last place you clicked is the game scene
Yep, it is. I’ve clicked a lot in there.
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.
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
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.
yeah well i didnt think it would matter as it didnt at my test there must be something obstructing it
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.
then have rigidbodies on them and jsut set them as IsKinematic
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: Unity - Scripting API: Rigidbody.isKinematic
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.
