Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Exnihilon · Apr 12, 2014 at 09:52 PM · androidresolutionscaleguitextureguibutton

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):

alt text

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:

alt text

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.

scatterguiandbuttons.jpg (16.6 kB)
guitexturenbuttons.jpg (52.6 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ForeignGod · Apr 13, 2014 at 12:42 AM 0
Share

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?

avatar image Benproductions1 · Apr 13, 2014 at 12:07 PM 0
Share

Why can't btnTextureX be an array?

avatar image Exnihilon · Apr 13, 2014 at 10:09 PM 0
Share

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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges