- Home /
Resize GUI for older iPhone versions
Hey guys, I'm working with an iPhone 4. The native resolutio is 960*640.
Now I am a bit struggling with the resizing of GUITextures for older iPhone models.
I found in another answer this code:
function OnGUI () {
GUI.Box (Rect (0,0,100,50), "Top-left");
GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-left");
GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");
}
and it works. But how can I do the same with GuiTextures instead of Gui Boxes?
Answer by jasielmacedo · Aug 14, 2012 at 03:12 PM
I found in another post this code:
public float native_width = 960;
public float native_height = 640;
void OnGUI()
{
if(Application.platform == RuntimePlatform.IPhonePlayer)
{
float actual_height = Screen.height;
float actual_width = Screen.width;
float ry = actual_height / native_height;
float rx = actual_width / native_width;
GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (rx, ry, 1));
}
// your GUI code here
}
Reference: http://answers.unity3d.com/questions/20782/scale-gui-without-moving-position.html
Answer by SolidSnake · Aug 17, 2012 at 03:00 PM
If you want simple scale then you can set the matrix like this at the beginning of your OnGUI function:
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,new Vector3(Screen.width / 640.0f, Screen.height / 960.0f, 1));
In this case your GUI will scale down accordingly
You only need to focus on one resolution (in this case 640 X 960) for your GUI work
Your answer
Follow this Question
Related Questions
Resolution for assets on Android 1 Answer
iPhone 4 and 5 resolution 1 Answer
Anti Alliasing is affecting an part of my GUI negatively 0 Answers
Rescale GUITexture Android/IOS 1 Answer