- Home /
Orthographic Static 2D Background - IOS/Iphone 3,4 & 5
Does any man, women or child now how I would go about setting a simple 2D background that doesn't move but adapts to its screen resolution? Iphone - 320*480,640*960, 640*1136? (Portrait)
I know there script that asks if(Screen.width == the iphone specified){ }
but is there a simpler way of doing this kind of like a guiTexture set to 1, 1, 1 which adapts to its screen size?
Help would be saaaaawweeeeet! thanks!
Answer by IronFurball · Nov 10, 2012 at 11:09 PM
There's a really simple way of doing this.
OnGUI()
{
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),yourTexture);
}
another way om making sure your game fits all resolutions is by designing your gui for a specific resolution(by example 800 * 600), and then using GUIMatrix, which automatically scales everything made with unity's OnGUI function.
now, i don't know exactly how GUIMatrix works but this should do the trick:
var horizRatio = Screen.width / 800;
var vertRatio = Screen.height / 600;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (horizRatio, vertRatio, 1));
Keep in mind when using GUIMatrix that your designing for a specific resolution and you dont have to use calculations such as Screen.width/2 + offset or something like that.
instead just give the exact position values and size values, the GUIMatrix wil do the rest.
Hope this helped !:)
sounds good to me, i glanced over GUI matrix once but I think i'll give it another go..I was warned about its unreliability with ios though as it doubles the draw cell count...and would the GUI not place itself in front of the actual gameobjects etc or can you set its z-index??
im terribly sorry, i didnt think this through enough, the gui is indeed in front of everything as far as i know. im quite busy at the moment but maybe this can help you futher: http://answers.unity3d.com/questions/9729/how-can-i-display-a-flat-background-2d-image-not-a.html
again im verry sorry, i guess i wasnt paying enough attention :P