Rect is not in correct place.

Hello, I am building the menu system for a game I am making. I am trying to setup a Rect that will turn off raycasting when the mouse is over it. This will keep clicks in the menu from passing raycasts through to the scene.

//Create a Rect to act as a Mask for the mouse.
		raycastMask = new Rect(mainMenuLeftAnchor,Screen.height - mainMenuSizeY,mainMenuSizeX + buttonBarSizeX,mainMenuSizeY);
// Set a bool to true if the mask contains the mouse.
		raycastAllowed = raycastMask.Contains(Input.mousePosition);
//Pass that bool to the camera to disable/enable raycasts.
		spaceCamera.SetRaycasting(raycastAllowed);

Since the Rect may have been in Screen coordinates I have defined the Rect this way also:

Rect(mainMenuLeftAnchor,mainMenuSizeY,mainMenuSizeX + buttonBarSizeX,mainMenuSizeY);

The odd thing to me is that both Rects are placed in the top left of the screen.

Here is a visual:

Any help is appreciated!

Use Event.current.mousePosition for GUI coordinates. Input.mousePosition is in screen space and should not be used with OnGUI code.

–Eric

Thanks! That isn’t really covered in the documentation.