• 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 Jeezker · Apr 27, 2014 at 01:23 PM · gui text

GUI TEXT looks smaller on higher resolutions! HELP!

Hello, first of all thank you for clicking on this.

I've made a scoring system for my game that is brought to "life" using GUI TEXT, unfortunately, on my high resolution HTC One, or any other high resolution phone, the text looks smaller, and on low resolutions, the text looks bigger.

Is there a way I could keep the proportions on any resolution, just like the 3d text does?

thank you very much!

the script: using UnityEngine; using System.Collections;

 public class PlayerScore : MonoBehaviour {
     
     
     
     public int score {
         
         get;
         
         private set;
         
     }
     
     
     
     public int bestScore {
         
         get;
         
         private set;
         
     }
     
     
     
     private Vector3 startPosition;
     
     
     
     void Awake() {
         
         
         
         startPosition = transform.position;
         
         bestScore = 0;
         
     }
     
     void OnGUI() {
 
 
         
         GUI.color = Color.black;
         
         GUILayout.Label("Score: " + score.ToString());
         
         GUILayout.Label("Best Score: " + bestScore.ToString());
         
     }
     
     
     void Update() {
         
         
         
         score = Mathf.RoundToInt(Mathf.Abs(transform.position.x - startPosition.x));
         
         bestScore = Mathf.Max(score, bestScore);
         
     }
 
 }
 
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

Answer by l3fty · Apr 27, 2014 at 04:11 PM

If you were using a GUIStyle for your labels, you could set the font size in the editor, or dynamically within the script.

For example:

 public GUIStyle myStyle;
 
 void OnGUI() {
 
     myStyle.fontSize = 40;
 
     GUILayout.Label("Score: " + score.ToString(), myStyle); 
 }

This example uses a simple value of 40 for the size, though you could use the current screen resolution to determine the actual value to use. Also you probably wouldn't want to set it every gui frame in OnGUI, I've just done that here for clarity.

Here's an example of how you might determine the size on any resolution. When building my GUI's I assume a default resolution height of 1080;

 float screenRatio;
 
 Start () {
     screenRatio = Screen.height / 1080.0f;
     myStyle.fontSize = Ratio ( 40 );
 }
 
 int Ratio( int pixelHDValue ) {
    return Mathf.RoundToInt( pixelHDValue * screenRatio );
 }
Comment
Add comment · Show 1 · 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 Jeezker · Apr 27, 2014 at 04:39 PM 0
Share

didn't help, please add it to my script cause It doesn't work for me and I'm new to all this so it's probably my fault.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 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

Related Questions

GUI script for Wave start. 1 Answer

How do i link a GUI text to a variable text which is a integer? 2 Answers

GUI Text doesn't render 1 Answer

Project R-a-B: Cannot drag Count Text into PlayerController.cs 1 Answer

GUI Text Problem 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