resolution differences between GameView, and build

in my game I am setting my GUI to display to the screen so that resolution does not matter. I have done all of my initial setup work based on 800X600, but instead of just constants I am first setting universal constants based on resolution, and then just doing math based on that. for example:

void OnGUI(){
    float width = Screen.width/8; float height = Screen.height/6;
    float wSpace = width/10; float hSpace = height/10;
    GUI.Box(new Rect(width*2+wSpace*2, height+hSpace*2, width*2+wSpace*2, height),
        "welcom here is some text that will" + '


+ “show up @800X600 in the GameView,” + ’

+ “but in a build it will be clipped off,” + ’

+ “and the window will be pinched”);
}
this way I can just run through and set all of my Rects based on multiples/addition/subtraction, of these instead of calculating hard numbers for each thing, and then when the resolution changes having nothing work right.

this all works perfectly in Editor/GameView, but when I do a build, and open the build at the target resolution nothing matches what I had set.

  • text boxes are pitched
  • buttons don’t line up
  • things are clipping through boxes, groups, and screen boundries

I can maybe see instances why at lower resolutions these calculations don’t particularly work, but why at the target resolution that I am checking against is it inconsistent between Editor/GameView, and Build?

Edit corrected incorrectly copied division of contants

adding picture:

running the same code. left is build right is GameView how are these different then?

The only way I’ve found out to make any UnityGUI bend to my will is by using percentages. That way you don’t have to care about resolutions; if something is 10% (of the Screen width) off the left edge of the screen, it’ll be 10% no matter the resolution.

The way I achieve this is have a bunch of global Rects, one for each gui element and make a method for calculating all positions for the Rects, which is called on a resolution change.

	void OnGUI(){
		CheckResolutionChange();
		
		GUI.Button(startGameButtonRect,"Start!");
	}
	
	void CheckResolutionChange(){
		if(oldWidth != Screen.width || oldHeight != Screen.height){
			CalculateRects();
			oldWidth = Screen.width;
			oldHeigh = Screen.height;
		}		
	}
	
	void CalculateRects(){
		startGameButtonRect = new Rect(
			Screen.width*0.1f /*10%*/, 
			Screen.height*.5f-Screen.height*.1f /*centered, as button height == 20%*/, 
			Screen.width*.2f,
			Screen.height*.2f);
	}

EDIT: I had this issue both in the game view and the build, using the code you provided. After some playing around, I made my own guiskin and set the font for the default box (which you are using) as 12pt Arial. This seems to have fixed the issue.