Screen.width not returning the right values

My computer screen resolution is 1920x1080. So if I use Screen.width, it should return 1920, right?

However, when I enter it into my script, it returns 416 instead. Any one has any idea why this is so?

boxWidth = Screen.width*0.25f, //Width of GUI background box

This is suppose to be the width of my GUI box, but it shows 104 instead of the expected value, 480.

I assume you have set the Unity resolution to 1920x1080? I created a project and tried it out with your code and I get a result of 408.75. If I build the project and run it, I get 480 as a result. Not sure if there is a bug or a way around it but it looks like you'll have to test build fairly often.

2 Answers

2

Screen.width returns the width of the game’s view and not the actual screen itself.

Correct. For the Desktop resolution, try [Screen.currentResolution][1] instead. [1]: http://docs.unity3d.com/Documentation/ScriptReference/Screen-currentResolution.html

Probably because the size of your Game view is in Free Aspect and it isn’t being maximized on play.