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
not had a chance to try your script but I'm pretty sure you don't want the lines in which you transform/move the camera. Try commenting them out and see what happens, also switch between your Scene and Game tabs to see what's going on.
– anon61858128