You can enable auto sizing for text with Best Fit. The Best Fit feature allows you to set a minimum and maximum font size for the text element. The text element adjust its font size dynamically based on the content and available space within the range.
Best Fit also supports the following features:
You can enable auto sizing in UI Builder, USS, or C# scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary.
In USS, set the -unity-text-auto-size property to best fit with a minimum and maximum font size. For example:
.labelText {
-unity-text-generator: advanced;
-unity-text-auto-size: best-fit 5px 100px;
}
To enable auto sizing in C# scripts, use the TextAutoSizeMode property. For example:
textElement.style.unityTextAutoSize = new StyleTextAutoSize(new TextAutoSize(TextAutoSizeMode.BestFit, minSize: 10, maxSize: 100));