I would like to know how it could be done with lesser cost. Sure I can check if coordinates of cursor are in the specified area (compare x and y) but it will be at least 8 logical comparisons in my case and not efficient at all. Any ideas?
Use Rect.Contains
function OnGUI() {
var BoxRect = new Rect(100,100,100,200);
GUI.Box(BoxRect,"My GUI Box");
if (BoxRect.Contains(Event.current.mousePosition))
{
// Whatever you want
print("Mouse inside");
}
}
Use Rect.Contains.
I suppose it’s done so the eight tests are not done if it’s unnecessary.