Resolution Issues

Hello there, I’m trying to make a simple script with the camera moving when the mouse is against the top of the screen.

var moveRate = 2.0;
var scrHeight = Resolution.height;
var scrWidth = Resolution.width;

function Update ()
{
if(Input.mousePosition==scrHeight)
{
transform.Translate(0,moveRate,0);
}
}

That’s my code, however when I try to do that, I receive two errors; “Assets/Standard Assets/cameraControls.js(2,28): BCE0020: An instance of type ‘UnityEngine.Resolution’ is required to access non static member ‘height’.”

Could someone please inform me of a fix to this problem? Thanks. :smile:

Resolution is a class, you need the resolution of the particular instance of that class that represents the screen.

try:

Screen.height
Screen.width

These two variables are static and therefore accessible from the class and not requiring an instance of the class.

I tried it, didn’t work. Thanks for helping, here is updated code. :slight_smile:

var moveRate = 2.0;
var scrHeight = Screen.height;
var scrWidth = Screen.width;

function Update ()
{
if(Input.mousePosition==scrHeight)
{
transform.Translate(0,moveRate,0);
}
// End of the code bits for screen movement.
}

The mouse coordinates start at zero, so the Y coordinate of the last line on the screen is actually Screen.height - 1.