- Home /
Making a tray GameObject that slides out on mouse over
I'm making a scene where when you hover over the top corner, the tray slides into the scene, then slides out when you move the mouse off of the tray. I have that working smoothly with:
function OnMouseOver () { while (transform.position.x > 4.0) { transform.position = transform.position - new Vector3 (0.1, 0, 0); yield WaitForSeconds (0.1); } }
function OnMouseExit () { while (transform.position.x < 12.0) { transform.position = transform.position + new Vector3 (0.1, 0, 0); yield WaitForSeconds(0.0001); } }
However, I plan on adding other clickable objects on top of the tray, and when I hover over those objects, it counts as an "OnMouseExit" and closes the tray. What's the best way to avoid this but keep the objects clickable?
Answer by Statement · Mar 13, 2011 at 04:09 AM
You could have a short timer that must expire before closing the tray which is reset in OnMouseOver to work around this issue. Maybe you can fix it using Invoke and CancelInvoke?