• 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 Rosonator · Dec 05, 2012 at 11:06 AM · guitextsizelabelguiskin

Relate font size to screen size in GUISkin

Hello everybody.

I have an annoying problem, and the worst is that I can figure that it'll be something obvious enough to make me feel embarrass once I get the answer. Anyway, lets go to the issue.

I'm making a simple GUI for an android application. I have related my buttons, text fields and boxes size to the Screen.width and Screen.height to keep the proportions and relative size. The problem comes because I don't know how to do the same with the texts (from labels and also from inside any element), which is not reduced when I reduce the screen size.

It's really a problem that must be solved because if I reduce the screen size to a normal Android phone the text inside textfield becomes bigger than the field itself.

I hope somebody knows how to solve this and wants to help a poor programmer as me. (tears) :D

Best wishes for everybody,

Alex.

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

2 Replies

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

Answer by GuyTidhar · Dec 05, 2012 at 12:58 PM

  1. You could use GUI.matrix to scale the whole gui, instead of your way of scaling the buttons, text fields and buttons, and that will include the font.

  2. You could have a list of supported screen sizes coupled with support font size, and when the the screen size is identified, choose the correct font size (need a dynamic font for that).

using the matrix example (option 1):

 float originalWidth = 1024;
 float originalHeight = 768;
 void OnGUI()
 {
   // Set matrix
   Vector2 ratio = new Vector2(Screen.width/originalWidth , Screen.height/originalHeight );
   Matrix4x4 guiMatrix = Matrix4x4.identity;
   guiMatrix.SetTRS(new Vector3(1, 1, 1), Quaternion.identity, new Vector3(ratio.x, ratio.y, 1));
   GUI.matrix = guiMatrix;
 
   // Do you GUI here
 
   // Reset matrix
   GUI.matrix = Matrix4x4.identity;
 }
Comment
Add comment · Show 5 · 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 Rosonator · Dec 05, 2012 at 03:41 PM 1
Share

$$anonymous$$an, this worked great. Thank you very much, again. Good luck!

avatar image GuyTidhar · Dec 05, 2012 at 03:49 PM 0
Share

Glad to have helped man!

avatar image 07Mr07 · Feb 01, 2014 at 11:37 AM 0
Share

$$anonymous$$ight you give an example with a Gui.button pls? I don't understand how it works thanks :D

avatar image Caviarail · Apr 11, 2014 at 06:50 PM 1
Share

Thank you big time!

avatar image mones88 · Apr 28, 2014 at 03:26 PM 0
Share

Thank you very much!! Do resetting the matrix really necessary? I've not seen differences commenting that line out.

avatar image
0

Answer by Rosonator · Dec 05, 2012 at 02:17 PM

That seems to be a real solution, and much cleaner than mine, I'd say. Thank you so much.

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

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

13 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

Related Questions

Changing a GUILabel text SIZE 3 Answers

Changing the size of a GUI label 1 Answer

GUI label/text appear/disappear 1 Answer

Can't draw GUI.Label text on subpixel values 0 Answers

Is there a way to get the size of text? 1 Answer


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