Why doesn't Unity like my rectangles?

So I’m having some trouble with one of my rectangles. Here are the rectangles I’m using:

var leftHandRect = Rect.MinMaxRect(0.22*Screen.width,(2/3)*Screen.height,0.4*Screen.width,Screen.height);
	var rightHandRect = Rect.MinMaxRect((2/3)*Screen.width,(2/3)*Screen.height,0.83*Screen.width-1,Screen.height);
	var bothHandRect = Rect.MinMaxRect(0.4*Screen.width,(2/3)*Screen.height,(2/3)*Screen.width,Screen.height);

The code works fine for leftHandRect, I haven’t added functionality to bothHandRect yet so I can’t test that, but it doesn’t like rightHandRect at all. When I first tried it out, I had slightly different rectangles, and the left one was working fine, but the right one did nothing. (When I say working, I mean using leftHandRect.Contains to check a touch event and then do something. I know the ‘do something’ code works, cos it was working earlier and works with the left hand rect, but now that the right hand rect is the way it is, it takes over and picks up every touch event no matter where it is on the screen, and the bounds of the rect are clearly not the whole screen. Any ideas? Cheers

Ok so I figured it out.

2 things to note:

  • Unity doesn’t like fractions of Screen.width and Screen.height. Perhaps a bug, or not rounding pixels correctly.
  • And secondly, there’s an error in the reference for Rect. At least for Rect.MinMaxRect, xMin and yMin are actually the bottom left hand corner, not the top. Hope this helps some people! And hopefully someone from Unity will see this and update the reference! (I don’t know how to contact them directly).