Orthographic cameras and screen resolutions

Hi,

This was originally posted as a question on the forums, but sank without a trace and with no responses, and I thought it might be better suited to unityanswers instead.

I've had a good trawl through various forum posts and other questions on this, which has partly helped me to get to the point I am at now. I am trying to create a simple window using an orthographic camera where the bottom left corner has coordinates of (0, 0, 0) no matter what the actual window size/screen resolution. So far I have produced the following script:

function Start()
{
resolutionCounter=0;

Screen.SetResolution(Screen.resolutions[0].width, Screen.resolutions[0].height, false);

Camera.mainCamera.orthographicSize = Screen.height/2;
Camera.mainCamera.transform.position = new Vector3(Screen.width/2,Screen.height/2,-100);

referenceObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
referenceObject.transform.position = new Vector3(10,10,10);
referenceObject.transform.localScale = new Vector3(10, 10, 10);
}

function Update () 
{

    if (Input.anyKeyDown)
    {

         if (resolutionCounter<Screen.resolutions.Length-1)
         {
            resolutionCounter++;
         }
         else
         {
              resolutionCounter=0;
         }

         Screen.SetResolution(Screen.resolutions[resolutionCounter].width, Screen.resolutions[resolutionCounter].height, false);
         Camera.mainCamera.orthographicSize = Screen.height/2;
         Camera.mainCamera.transform.position = new Vector3(Screen.width/2,Screen.height/2,0);
     }
 }

This code allows me to cycle through the supported resolutions properly. However, it doesn't keep the created sphere 10 pixels from the bottom and left of the window, which I thought should be the case no matter what resolution is chosen. In fact, the sphere jumps all over the place, and is sometimes not in the window at all.

Am I doing something wrong here, or is my understanding of what should be happening incorrect?

Thanks,

Wibbs

Okay,

I've found the answer to this. Screen.width and Screen.height seem to lag behind and were not being updated in time for changing the camera's orthographic size or position in the same Update call. I replaced these lines with:

Camera.mainCamera.orthographicSize = Screen.resolutions[resolutionCounter].height/2;
Camera.mainCamera.transform.position = new Vector3(Screen.resolutions[resolutionCounter].width/2,Screen.resolutions[resolutionCounter].height/2,-100);

and now everything works as expected, with world space giving the same x,y coordinates as camera space.