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?

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.

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.

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.

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.