- Home /
How-to-make-GUI-Buttons-on-GUI-Texture-resolution-independent
Hello everyone. I am newbie to Unity and Android developent, and I am in need of your help to make my GUI controls resolution independent.I have posted the same question on the Android development forum, but I got not responce, so I am posting here with code, for better.
I have a GUI Texture in my scene to be used as a graphical background for a controller, and above this, a set of GUI buttons is rendered in absolute x,y screen positions. Those two elements rendered together makes the buttons controller for my android application, in a 480x320 HVGA Landscape screen resolution(see image 1):

The problem is that if the resolution is changed to 800x480 WVGA Landscape, everything is meshed up as you can see in the following screenshot:

I have tryed to make use of the Matrix4x4 to keep the GUI buttons scaled to a new resolution, but I still get them scattered all around screen.
Could anyone be kind enough to give some advise or maybe a code snippet on how to make both GUI buttons on absolute possitions and GUI Texture, screen resolution independent?
These is the script for rendering the GUIButtons above GUITexture:
 using UnityEngine;
     using System.Collections;
     
     public class GUIButtons : MonoBehaviour {
         
         public Texture btnTexture1;
         public Texture btnTexture2;
         public Texture btnTexture3;
         public Texture btnTexture4;
         public Texture btnTexture5;
         public Texture btnTexture6;
         public Texture btnTexture7;
         public Texture btnTexture8;
         
         
           void OnGUI()
             {
             
             if (!btnTexture1) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
                  GUI.Button(new Rect(68, 219, 50, 35), "");
             
             if (!btnTexture2) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
                 
             GUI.Button(new Rect(130, 219, 50, 35), "");
             
             if (!btnTexture3) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
             GUI.Button(new Rect(68,262,50,35), "");
             
             if (!btnTexture4) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
                 GUI.Button(new Rect(305, 219, 50, 35), "");
             
             if (!btnTexture5) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
                 GUI.RepeatButton(new Rect(366, 219, 50, 35), "");
                     
             
             if (!btnTexture6) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
                 GUI.RepeatButton(new Rect(130,262,50,35), "");
             
             if (!btnTexture7) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
                 GUI.Button(new Rect(305, 262, 50, 35), "");
             
             if (!btnTexture8) {
                 Debug.LogError("Please assign a texture on the inspector");
                 return;
             }
                 GUI.RepeatButton(new Rect(366, 262, 50, 35), "");
             
         }
     }
 
Thank you all in advance for your answers.
im not too familiar with C# but when you added the $$anonymous$$atrix4x4 you made sure to have it in the top of your gui function?
Hi Crawlier. I have tried and added $$anonymous$$atrix4x4 on top of OnGUI but it does not respond as it should. The problem I think is this, I have a compilation of a GUITexture and a GUIButtons. Those two are making my controller buttons in the scene. There must be a way to have those two elements scaled simultaneously from the original 480x320px to 800x480px screen, but I am novice in Unity and program$$anonymous$$g, so I am asking for help here.
Your answer
 
 
             Follow this Question
Related Questions
Android GUI resize problem 1 Answer
Scale menu to fit webplayer with fullscreen on/off 0 Answers
Bulletproof way to do resolution independant GUI scaling? 2 Answers
Scaling problem android 1 Answer
[Android] Screen Scaling?! 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                