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 Therian13 · Jan 19, 2015 at 07:31 AM · buttontextresolutiononguigui-button

OnGUI button changes size for resolution, but text doesnt?

Hello Everyone,

I am currently working on a series of GUIs for my game, and I have come across a strange error.

I have all my GUI buttons on Screen.width/#, etc, so that they change correctly for different screen resolutions, but the texts that are on the buttons do not.

Is there anyway to fix this? Any help would be greatly appreciated.

Here is how I am writing it. (the rest of the script is pretty much just repeats of this.

 if(GUI.Button(Rect(Screen.width/2.5,Screen.height/2,Screen.width/10,Screen.height/20), "Cancel Quest"))
             {
                     {
                     questNumber.questNumber = 0;
                     questNumLooking =0;
                     questSelected = false;
                     checkingQuest = false;
                     drawGUI = true;
                     }
                 }
             }


Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by zharik86 · Jan 19, 2015 at 07:33 AM

Of course, font size don't change. Simple solution: create new GUIStyle in Inspector and change font size in Start(). Or for your case best of all the following code will approach. For example, you have LandScape orientation and for the size screen 1920 the size of the text is equal 40. Then:

  public GUIStyle myStyleBtn = null; //reference on your style for button

  void Start() {
   myStyleBtn.fontSize = (int)(40.0f * (float)(Screen.width)/1920.0f); //scale size font
   //or you can create style in program
  }

  void OnGUI() {
   //and use style for your button
   if(GUI.Button(Rect(Screen.width/2.5,Screen.height/2,Screen.width/10,Screen.height/20), "Cancel Quest", myStyleBtn)) {
    //...
   }
  }

Probably, it is better for you to use GUI.matrix for scaling of all GUI elements. Or update Unity and use new UI. I hope that it will help you.

Comment
Add comment · Show 3 · Share
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 Therian13 · Jan 19, 2015 at 08:10 AM 0
Share

but wouldn't that change the font style to only work with people who have a 1920X# screen?

avatar image Therian13 · Jan 19, 2015 at 08:13 AM 0
Share

ah, never$$anonymous$$d, I think I see now. It changes the number based from my own screen resolution to match the current screen width...

sorry, since it was in c# it threw me off a bit. I'll give it a try and let you know.

Thank you for the script also. I think I can convert it to JS.

avatar image Therian13 · Jan 20, 2015 at 02:09 AM 0
Share

Works like a charm! Thank you zharik86!

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

2 People are following this question.

avatar image avatar image

Related Questions

UI Button Instead of OnGUI Button? 1 Answer

Bold and italic and other combinations in GUI Button or Grid? 0 Answers

Gui button doesnt show 1 Answer

Cannot click UI button. 4 Answers

My dialogue system has a strange bug 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