Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 $$anonymous$$ · Feb 17, 2019 at 06:23 PM · textuser interfacescaling

Scale UI Text

I've been having an issue with my User interface for some time now. When ever i scale the canvas, the text remains the same size and its messes with everything. If i try to scale the text in a script like this :

 public Canvas Reference;
     public Text WIPTxt, MainMenuTxt;
     public float SF, tmp;
     void Start () {
         if (Reference.scaleFactor != 0)
         {
             SF = Reference.scaleFactor;
         }
         else
         {
             SF = 1;
         }
         TESTTEXT.text = SF.ToString();
         tmp = WIPTxt.fontSize;
         tmp *= SF;
         WIPTxt.fontSize = (int)tmp;
         tmp = MainMenuTxt.fontSize;
         tmp *= SF;
         MainMenuTxt.fontSize = (int)tmp;
 }

The text becomes exponentially smaller with the decrease in resolution. The next thing i tried was Content Size Filter. This just ruined everything so im not going near it again. Which leaves me here. I have no idea what to do so im hoping someone here can point me in the right direction because i am clearly missing something,

Comment
Add comment · Show 13
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 RobAnthem · Feb 17, 2019 at 06:27 PM 0
Share

Out of curiosity, are you trying to scale it based on screen size? I came up with a script that scales UI elements by screen size, using a ref size.

 using UnityEngine;
 
 public class SceenSizeScaler : $$anonymous$$onoBehaviour {
     public Vector2 refSize;
     void Awake()
     {
         Vector3 size = transform.localScale * (Screen.width / refSize.x);
         transform.localScale = size;
     }
 }

And to get ref size

     [$$anonymous$$enuItem("Tools/Current Screen Size")]
     public static void ShowScreenSize()
     {
         Debug.Log("Screen Dimensions are: X: " + Screen.width + ", Y: " + Screen.height);
     }
avatar image $$anonymous$$ RobAnthem · Feb 17, 2019 at 07:42 PM 0
Share

By default, the resolution within the Canvas Scaler is set to 1920x1080. This scales everything on the UI already so i have no issues with this at all. The issue comes from the Text font size, which is what im trying to modify within the script in my answer. $$anonymous$$y train of thought was, If the screen resolution decreases, then the scale factor would decease one. I could then take this value, and multiple it with the font size to get a scaled font size. But this becomes too small.

Edit: One solution i keep seeing is the "Best Fit" property. I really dont want to use this as it makes all the text on the screen appear different sizes and just looks messy.

avatar image Ymrasu $$anonymous$$ · Feb 18, 2019 at 12:08 AM 1
Share

In my experience with UI Text, it's best to pick a high font size then scale the transform of the text object.

Show more comments
avatar image zereda-games · Feb 18, 2019 at 12:14 AM 0
Share

On your canvas set int the Canvas Scaler Script, set the Ui Scale $$anonymous$$ade to "Scale with screen size" now try. if thats not quite it, adjust you anchor points.

alt text

alt text

you will notice my buttons do not scale this is because i set them to center pivot for this example. the Full Games Pack Text Component is on an empty game object on the canvas background image that is on the canvas itself. what a mouth full Background expands the whole canvas, and empty object is set to expand width only and only because myself was getting an odd expanding error where the Full Games Pack Txt was moving up and down on screen size change, and i didn't like that so i locked the empty game object to be stuck at the top of the background and expand width only and the text component expand on it in full

example-b.gif (93.6 kB)
example-a.gif (89.8 kB)
avatar image $$anonymous$$ zereda-games · Feb 18, 2019 at 12:16 AM 0
Share

I've done this on all the Canvas' in my scene but this doesn't work. The actual text field scale with the screen size, but the font size doesn't change. This leads to text boxes appearing empty because the text doesn't fit.

avatar image zereda-games $$anonymous$$ · Feb 18, 2019 at 12:17 AM 0
Share

are you setting the font size in code? try removing it and set the text component to best fit and have a max and $$anonymous$$ size.

Show more comments

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

105 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 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 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 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 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

How should I go about proper GUIText scaling for mobile devices? 0 Answers

UI Text Small on screen device. 1 Answer

Is it possible to change Outline at runtime? 1 Answer

Why does my scene looks different when I run a WebGL build ? 1 Answer

I made a text object in a script but Unity doesnt let me place the UI text in the box. 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