- Home /
Resize all UI texts fontsize in a scene with one command?
I have several hundreds of UI texts in my 2D game. Having used the new UI system all trough the game looks the same on all devises apart from two things that I would like to fix in a time effective way. The first is the font sizes. Of course I could drag all of them to my game object in inspector and attach a script telling every text to resize accordingly to resolution ov the device. ...or is it a way to call ALL text.fontsize in a scene at awake() without having to drag in inspector?
I have the sam problem with the built in UI shadow scripts that I have attached to everything (including all text). I want to be able to resize them in a elegant way aswell.
Answer by Xarbrough · Apr 28, 2015 at 10:30 AM
If you'd really really want to you could find all UnityEngine.UI.Text components with FindObjectsOfType(), but this will totally kill your performance at runtime if you have a lot of text objects.
API reference FindObjectsOfType
The better solution would be to make use of the dynamic scaling abilities of the new UI. There's the Canvas Scaler, Content Size Fitter and Layout Group with Layout Element. Text can also have Best Fit with min and max size. This in conjunction with correct anchoring should give you a scalable UI. See: Unity Manual HowTo Design for Multiple Resolutions
Ok thanks! $$anonymous$$y intention is to resize all texts and shadows at startup.. It shouldnt take much time..? And after that it shouldnt take any off my performance, right?
Everything in my UI resizes perfectly exept texts and shadows... I have found out the hard way that Best Fit lags my game terribly, and there is also very difficult to get the same size of the text in different text fields, buttons etc.
Im gonna have a look at the link you sent now.
Canvas scaler did the trick for me! I changed it from "constant pixel size" to "scale with screen size".
Your answer
Follow this Question
Related Questions
How to understand if 4.6 UI button is highlighted? 3 Answers
UI: Loading the text in a Text type with a String? 1 Answer
Why are my Unity UI fonts rendering incorrectly? 4 Answers
Help Changing GUI Text size 0 Answers
Measure text size for UI Text 1 Answer