Screen.width, Screen.height not working propertly

Hi Guys! I’ve got problem with that Unity GUI.

I’ve created menu for my game and it fits in my native resolution. But not everyone have my resolution, so I used “Screen.width” etc.

Code:

GUI.Box(new Rect(Screen.width/2 - 1002, 0, Screen.width/2 - 500,  Screen.height), "Menu");
	      if(GUI.Button(new Rect(Screen.width /2 - 850,Screen.height /2 + 80,250,50), "Main Menu"))

End rest of the buttons, and boxe’s were made the same way.
I know, there aren’t any braces, but i’ve posted this only for “(Screen.width/2[…]” etc

Everything should work fine, but… it isn’t…

I’m getting, something like this:

It isn’t scaling, to the right resolution…

Thanks for help, and sorry for my bad english.

This may be because it’s running in a window and not fullscreen. You could try the pixelWidth and pixelHeight properties of the current camera instead.

1 Like

It isn’t working too… In editor, there is the same thing as in window.

BTW:No matter, this is fullscreen, or window… it isn’t working anyway…

It’s because you’re using raw numbers. You still take 1002. I’d suggest only dividing and multiplying with screen.height/width so you get the same thing with each resolution.

Yeah, I resolved this a while ago. Now i understand this…
On every resolution it was substracting the same numbers, like 1002. Every resolution has different number of pixels, so it can’t resize well…

Anyway! Thanks for reply, now I understand :wink: