- Home /
How can I use Rect.Contains with GUI.Window?
Will the two work hand in hand? When I try to call Rect.Contains()
on a Rect inside a window, it always returns null.
I'm guessing that this is because Rect.Contains()
is using screen space, while the Rect inside a window is relative to the window's position. Is there an easy workaround for this, or do I have to create another Rect in screen space that is in the same position as the Rect inside the window?
Answer by getyour411 · Jan 28, 2014 at 05:28 AM
Since this remained unanswered and I hit upon it while searching for the same thing...
if(myRect.Contains(Event.current.mousePosition))
Debug.Log ("Mouse is in the rect!");
Some of the others posts I found were trying to use Input.mousePosition which required offsets and other calcs, using Event.current.mousePosition works nicely as it is relative to the Window space when called in the Window's supporting function.