- Home /
Window pops up when mouse is over a GUI.Label
I've got a GUI.Label which shows a Texture2D. I want it so when user hovers his mouse over the picture a window pops up where the mouse cursor is. Is something like this possible?
I've seen a OnMouseOver function, but as far as I understood it only works when you add a script with it to an existing gameObject. My labels are generated by script - depending on how many items are in the inventory.
Answer by illwunn · Aug 15, 2011 at 10:29 PM
i recently implemented something like this in one of my programs, i used Rect.Contains code, but i ran into a problem with the input.mouseposition.y being all weird, anyways try this:
Rect myRect = new Rect(100, 100, 20, 20);
void OnGUI()
{
GUI.Label(myRect, "random texture");
if(myRect.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)
{
GUI.Box(new Rect(x, y, width, height), "random message");
}
}
it uses the rect position to determine if the mouse is on the gui.label then draws a box if its true
I used Input.mousePosition.x, Screen.height - Input.mousePosition.y for x and y in the new Box and it follows the mouse while in the area. It lags a bit though, any way to stop it?
GUI.Box(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 200, 200), rectString);
thats how i did my tooltip box, and it doesnt seem to lag the box
Your answer
![](https://koobas.hobune.stream/wayback/20220612181518im_/https://answers.unity.com/themes/thub/images/avi.jpg)