Check GUI button status

Hi!

I need to check when my players are hovering on a GUI button so I can do some more stuff… simple. But I don’t know what to do and I can’t find anything about this. Do someone knows how I could do it?

Seems like there should be a way to do this directly. I know how it can be done indirectly. You can test the mouse position against Rect of the button. Something like:

#pragma strict

private var rectButton = Rect(0,0,100,50);

function OnGUI() {
	var e = Event.current;
	if (e.type == EventType.Repaint && rectButton.Contains(e.mousePosition)) {
		Debug.Log("Hoving over button");
	}
	if (GUI.Button(rectButton, "Button")) {
		Debug.Log("Button Pressed");
	}
}

Note I use the ‘Repaint’ event so that the code in the check will only be executed once per frame.