This is a common problem and there doesn’t seem to be a non-workaround answer:
I have a GameObject (nota GUIText or GUI anything, just a Cube with a rigidbody), it is a collider (isTrigger is off/deselected) it is also a rigidbody (isKinimatic is on/selected). I’ve got a script on the object (that definitely IS attached, and does NOT belong to the IgnoreRayCast layer, I double checked) with these functions defined:
public void onMouseEnter() {
print("onMouseEnter");
}
public void onMouseExit() {
print("onMouseExit");
}
No matter if I turn isTrigger on/off or isKinimatic on/off the onMouseEnter/Exit functions do not register
I also run this code in another script:
RaycastHit hitInfo;
if( Physics.Raycast( Camera.main.ScreenPointToRay( Input.mousePosition ), out hitInfo ) {
Debug.Log( "mouse is over object " + hitInfo.collider.name );
}
and it DOES register that the ray hits the object (regardless of isTrigger and isKinimatic being on or off). But then why won’t the onMouseEnter/Exit functions work? They are basically the same thing, right? Also, I have onMouseDrag()
implemented in the same script as onMouseEnter/Exit and that works perfectly!
What could I be doing wrong, I’ve tried (what I think) is everything(!)
p.s: I know I can use the raycast to get hold of what object is being selected but this is a workaround. I’d rather avoid workarounds since, according to Unity, onMouseEnter/Exit should work.
(http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnMouseEnter.html).