Just fixed weird mouse over detection problem but not really sure how

This code disables the mouse from rotating something when mouseOverMainMenu is true. Before I fixed it, the mouse was only being disabled over box1 and not when trying to rotate while hovering over infoBarBox.

I changed it from this…

if(box1open)
    {
    	Rect box1 = new Rect(box1X, box1Y, box1Width, Screen.height);	
            Rect infoBarBox = new Rect(infoBarX, infoBarY, infoBarWidth, infoBarHeight);
    	mouseOverMainMenu = (infoBarBox.Contains(Input.mousePosition) || box1.Contains(Input.mousePosition)) ? true : false;
    }
    else
    {
    	Rect infoBarBox = new Rect(box1X, box1Y, infoBarWidth, infoBarHeight + box1BarHeight);
    	mouseOverMainMenu = infoBarBox.Contains(Input.mousePosition) ? true : false;
    }

To this…

if(box1open)
    {
    	Rect box1 = new Rect(box1X, box1Y, box1Width, Screen.height);	
            Rect infoBarBox = new Rect(infoBarX, 0, infoBarWidth, infoBarHeight);
    	mouseOverMainMenu = (infoBarBox.Contains(Input.mousePosition) || box1.Contains(Input.mousePosition)) ? true : false;
    }
    else
    {
    	Rect infoBarBox = new Rect(box1X, 0, infoBarWidth, infoBarHeight + box1BarHeight);
    	mouseOverMainMenu = infoBarBox.Contains(Input.mousePosition) ? true : false;
    }

And it was fixed. But I don’t have any real idea as to why changing those two Y-values to 0 fixed it. Anyone know?

Rect.Contains uses a vector2 where 0,0 is the bottom left of the screen. GUI has 0,0 as top left of the screen. Changing the y value to 0 didn’t completley solve the problem as the GUI element will only work on one part of the screen. You need to invert the y axis using:

((Screen.height-box1Y)-infoBarHeight)

(line 4, change 0 to this)

This should work at any position on the screen