GUI rect inverted

I’ve come across, what I perceive, as a bit of strangeness. I have a game where the player shoots when they click the mouse button. I’ve created three GUI buttons at the bottom of the screen that allow the player to change the item being thrown. I would like to stop the mouse button from shooting when the player is selecting a new item so I used this script.

function OnGUI () { 
  	var rect0  = Rect (Screen.width/10*2.5,(Screen.height - Screen.height/10 - 10),Screen.width/10,Screen.height/10); 
	
	if (rect0.Contains(Input.mousePosition)){
        NoShoot = 1;
	}
	else {
        NoShoot = 0;
	}
	
	if (GUI.Button ( rect0, "ROCK")) {
		projectile = projectileROCK;
	}
}

The problem is that the button draws on the bottom of the screen while the ‘No Shoot’ area seems to be at the top of the screen, apparently inverted. Given that the two regions are created from the same var rect0, I’m a little lost. Even the manual seems to suggest that Rect.Contains is defined from the bottom of the screen and not the top.

Help would be appreciated.

Screen coordinates are bottom-up, and OnGUI coordinates are top-down…That’s Just The Way It Is™. :wink:

–Eric

Use Event.current.mousePosition within OnGUI instead of Input.mousePosition. It’s properly oriented, and always in the same space as whatever GUI elements would be drawn.

You learn something new everyday. Thanks for the information.

God f*cking damnit