- Home /
How do I Scale a GUITexture or GUIText for different resolutions screen sizes on the iPhone?
My "buttons" rescale perfectly with the code below using the OnGUI function, regardless of what iPhone or iPad I'm testing on. I added the GUI.matrix code line directly below the OnGUI function. My question is, How do I rescale a GUITexture or a GUIText? Since these game objects are created by Unity I'm unable to edit the script and add this line of code.
thanx
function OnGUI() {
GUI.matrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3(Screen.width/960f,Screen.height/640f,1f));
if (GUI.Button(Rect(30,210,170,55),"PLAY INTRO"))
Application.LoadLevel("sk38");
Time.timeScale =1;
}
Answer by Wolfram · Jun 25, 2012 at 02:01 PM
My answer here describes the approach for scaling GUITextures correctly for varying screen resolutions. In your case, option "2)" is what you are looking for. Although that answer only describes the scaling in detail, you can do similar computations for the positioning of your GUITextures.
GUITexts behave somewhat different, they ignore localScale and only use font size, and the positioning is done with localPosition (view space) and/or pixelOffset (screen space) from that localPosition, plus the given anchor property. I guess the fact that it's so complicated to deal with the "old style" GUIElements was one of the reasons (besides flexibility) to create the new UnityGUI classes.
An entirely different approach would use "real" 3D obejcts placed in a parallel plane as child to the camera in a normalized screenspace, see here for example.
What do you mean by "these game objects are created by Unity"? You still have to create these assets and place them in your scene. Note that OnGUI() is entirely unrelated to GUIText/GUITextures.
Your answer
Follow this Question
Related Questions
Dealing with GUI size on iPhone 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Scaling GUI When Screen Width is Adjusted 1 Answer
How to create a resizable GUI 1 Answer