- Home /
Screen.height & Screen.width returning strange values
I'm writing a script which disables the Mouse Look script when the cursor is moved outside of the player window, but:
Screen.width is returning the width of my full screen (1440) and Screen.height is returning 20
Has anyone else had this problem?
Answer by DocSWAB · Nov 15, 2010 at 05:36 PM
In Unity 3.0 and 3.1, if you are in the Editor, and you don't have a Game View open and active when you press Play, you will get bad values for the screen size when you start the game.
Answer by oliver-jones · Nov 15, 2010 at 05:59 PM
Yeah, I agree with Doc - It messes up if you resize the game window whilst playing too.
What I personally do is grab the game window as a separate window and make it a preferable size. Then play.
Answer by jstanley · Dec 02, 2010 at 05:44 PM
I was having trouble when I tried to enable my script by clicking "enable" -- Screen.width and height values were strange. Then I realized that the Screen Unity was using is the properties window where I had just clicked the enable checkbox. I set up a small test script to enable it without having to click that checkbox and everything worked fine. Seems that "Screen" is the last activated window.
Answer by Ranza · Feb 28, 2011 at 03:04 AM
What I've observed, at least in Unity 3.2 is that it depends who's calling Screen.width/Screen.height If you're calling it from inside of an Editor Script it will most likely return values of Inspector Window, I can guess that this is helpful when you're using EditorWindows and you'd like to know their sizes.
For now you can use a workaround: Make a function inside MonoBehaviour script which will set the screen size to a local variable and make that variable public/+static, call this function from Update/+Start MonoBehaviour script.
Your answer
Follow this Question
Related Questions
Player keeps falling through the floor and I'm really stuck 5 Answers
restrict mouselook X movement script does not work 4 Answers
MouseLook Problem 1 Answer
Freeze Mouse Look on Pause 4 Answers