- Home /
Show Gui button as hovered with custom mouse position
I'm using a custom mouse pointer that does not use the OS mouse position. This creates problems with the Unity Gui system, sepcifically buttons as they check for the actual mouseposition to display as Hovered and be clicked etc.
I was wondering if there was a way to check the GUI.Buttons with a custom mouse position such as mine, or if you can manually display a GUI.button as hovered (as it appears in the GUIStyle), in which case I could make a custom mouse over check as well.
EDIT: Seems I was being unclear. I want to use the Unity GUI system but I want to manually trigger the hover and active states of the GUI elements, instead of them being triggered by mouse over and clicked.
Answer by lbalasubbaiahapps · Oct 02, 2011 at 09:45 AM
you can use Onmouseenter and onmousehover also it will help you to your coustom
No, this is not what I'm after. $$anonymous$$aybe I wasn't clear enough: I want to use the Unity GUI but I want to draw a GUI.Button as hovered relative to my custom mouse position.
Answer by henry96 · Oct 02, 2011 at 03:17 PM
I think this is what you want to know. First, you will need to know the current position of mouse.
function OnGUI ()
{
var e : Event = Event.current;
Debug.Log(e.mousePosition);
}
So now you have it. Set that position x and y for the GUI.Box.
// Inside the function OnGUI
GUI.Box (Rect (e.mousePosition.x, e.mousePosition.y, 100,100), "");
Hope this helps. Enjoy!
No, that will draw a box at the mouseposition. What I want to do is have buttons that I can manually change the hover state on, ins$$anonymous$$d of the mouse doing this automatically