- Home /
OnMouseEnter over a Collider, what's the distance?
I'm trying to use OnMouseEnter (and Exit) on some colliders to be able to enable some GUI elements.
It works fine, when I'm within a certain distance (it seems). I don't see any way to tell Unity what that distance is (like you can with raycasting). I would think that no matter what the distance, if the mouse is over the rendered collider, it should get these mouse events.
I'm using a mesh collider which is a mashup of two cubes, one facing 'out' and one facing 'in', so that even if you are inside the cube collider, it should still detect the 'inside' faces and register a 'hit' (mouse is over it), right?
Hi, you need to be more specific because if you are trying to use the "On$$anonymous$$ouse" functions inside a big cube there always be in contact with the surface of the cube I don't think that's what you really want, I'm rong?
I don't think that your collider will work if your cube have inverted faces. Besides that On$$anonymous$$ouseEnter is only called once, the moment you're getting over the collider. if you are inside the cube (and the inverted cube is closed) it wouldn't matter in which direction you look, you're always "over" the collider. That means you can't "enter" or "exit" the collider. $$anonymous$$aybe just tell us what you are trying to archive...
It does, just not consistently, I'm trying to figure out why that is.
Answer by Eric5h5 · Jan 28, 2011 at 01:53 AM
The default raycast distance, which OnMouse events use, is Mathf.Infinity. i.e., there is no distance limit.
I thought so, because some of them trigger at any distance. Some I must get right up on, as though there were a shorter limit, or something else is occluding the hit. If I had part of another collision volume in the way, would that prevent On$$anonymous$$ouseEnter/Stay/Exit?
If it's being blocked by another collider, then yes, On$$anonymous$$ouseStuff won't fire, same as if you were raycasting manually. You can put colliders on the IgnoreRaycast layer and they won't block.