- Home /
How to know the font size, if in "Best fit" mode ?
my program has an input field, where I type a text and it writes on the screen, I put it in "Best fit" mode so that it works with different resolutions, but if I type a very large text, it will have a small font, I need to find a way that, before the text diminishes the font, breaks the line.
Answer by enestelli · Oct 06, 2020 at 09:38 PM
With: Text.cachedTextGenerator.fontSizeUsedForBestFit
This attribute is an integer. With this attribute you will be able to know the font size.
I'm using version 2018.4 of Unity and it doesn't have "cachedTextGenerator", but it does have "TextGenerator", which seems to have the same functionality. but I didn't understand how to use it, how do I create the variable and select the text I want to inform "fontSizeUsedForBestFit" ?
Suppose this is your variable.
Text text;
With the functionality you can access the text's font size.
int size = text.TextGenerator.fontSizeUsedForBestFit;
Your answer
![](https://koobas.hobune.stream/wayback/20220613013246im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Change Textmesh.text from script 2 Answers
3D Text Size Relative To Screen? 4 Answers
How to add Japanese 2D text to 3D world 1 Answer
Blender model ugly textur 1 Answer
Problems about GUI fontsize 1 Answer