- Home /
Check if Mouse Over Button in Editor
What is the best way to check if the mouse is over a button in an EditorWindow? The buttons I'm using are contained in an Area, which will have to be considered when calculating the button's position.
Example:
 Rect rectArea = new Rect(10f,10f,100f,100f);
 GUILayout.BeginArea(rectArea);
 Rect rectButton = new Rect(50f,100f,20f,40f);
 GUI.Button(rectButton,"Button");
 // if (Event.current.mousePosition == ?)
 GUILayout.EndArea();
I have offset the rectButton with the rectArea's position, but hovering over the button, the mousePosition is not close in value to the button's position. What am I missing here?
 if(rectArea.Contains(Input.mousePosition))
 {
        // mouse is over button now...
 }
im not sure if i have got ur question though..
Answer by absameen · May 31, 2012 at 02:50 PM
I've over-complicated the problem, this works:
 if(rectButton.Contains(Event.current.mousePosition))
Your answer
 
 
             Follow this Question
Related Questions
OnMouseOver UI Button c# 2 Answers
How to trigger button press on a button in an editor window by pressing the return key ? 0 Answers
Get position of Rect in Rect in EditorWindow 1 Answer
I want to target button with the camera and, after loading bar, activate button 1 Answer
'Button' is not a member of 'GUI' 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                