- Home /
Text box pop up on mouseover
Hi all, I've been searching the forums and answers for quite a while and haven't found quite what I'm trying to do. I'm trying to find a way to have a text box pop up with descriptive text when certain objects are moused over in the scene. For example, there will be a number of books scattered about and when the player puts the cursor on the book, the title of the book will be displayed in the pop up box. This artist who's a terrible coder would greatly appreciate the help. Thanks!
Answer by equalsequals · May 21, 2010 at 05:16 PM
In order for an object in 3D space to receive mouse events it needs a Collider component applied and active.
Once your object has a Collider, you must attach a Behaviour script which handles the event OnMouseOver (or OnMouseEnter, theres a bunch see which one is right for you in the docs).
The next step would be creating your popup box. There are a couple ways of doing this, depending on how you want to handle it, your can use Unity's immediate mode OnGUI() to draw it with a script similar to this:
private bool _mouseOver = false;
void OnGUI()
{
if(!_mouseOver) return;
//draw your GUI stuff here with Unity's OnGUI code - see ref for details
}
void OnMouseOver()
{
_mouseOver = true;
}
void OnMouseExit()
{
_mouseOver = false;
}
Another way to do it with just a GUITexture would be to use the OnMouseOver/OnMouseExit functions to show/hide a referenced GUITexture.
Hope that helps.
==
Thank you for the help! I just may be able to get this to work.