I have a Textmesh with a boxcollider on it which is sized just fine. When my mouse enters the collider, the OnMouseEnter() and the OnMouseOver() methods begin to execute. Nothing wrong there. OnMouseDown() also works perfectly. The only problem that I have is when my mouse goes to leave the collider area. The script never realizes that the mouse actually leaves. I tested this with a little code like so:
public bool isSelected = false;
TextMesh myText;
void Start()
{
myText = gameObject.GetComponent<TextMesh>();
}
void OnMouseEnter()
{
isSelected = true;
}
void OnMouseDown()
{
Application.LoadLevelAdditive("");
print("Click");
}
void Update()
{
if (isSelected)
myText.color = Color.yellow;
else
myText.color = Color.white;
isSelected = false;
}
When the mouse enters the collider, isSelected becomes true and the color of the text changes to Yellow, so I know that part works, but with it on OnMouseEnter(), I can check the status of the mouse entering every frame (I know that it should be OnMouseOver() later, this is for debug purposes.) Now,on the second frame after the mouse enters the collider, it changes to the color to White because the isSelected variable is set to false now. Great, works fine.
When the mouse supposedly leaves the collider, and reenters, the OnMouseEnter() method doesn’t fire because it thinks the mouse is still in the collider for some weird reason. Any suggestions as to why this might be, and potential fixes?
P.S. I can get the OnMouseExit() function to work properly on another script in a different scene.