- Home /
Is there a way to find the current font size of a Text?
I have two Texts, and I want the font size of the second one to be 80% of the first. The first one has 'best fit' checked. How do I find the current font size of the first Text?
Scripting reference doesn't seem to have anything. "fontSize" member reports the font size set in the editor, and doesn't update as the best fit logic happens.
If this isn't possible, then I need a way to set a font size and have the font object scale with resolution, instead of having a pixel-based font size. In other words, I'd want the size-10 font to be relative to Unity Units, not relative to Resolution Pixels.
I would think the font size on best fit is done right before rendering and probably not stored on anything accessible. At least, I have not seen.
For the second case, could using the canvas in world space be a solution? Converting the screen resolution into world space would be a start so already you have a ratio in world coordinate.
Answer by DiegoSLTS · Feb 09, 2015 at 12:24 PM
This was asked and answered here: http://answers.unity3d.com/questions/784199/how-to-get-the-current-best-fit-size-of-a-text-com.html
Answer by Mmmpies · Feb 09, 2015 at 11:48 AM
Why not just set the text box of the second object to 80% the size of the first one and set it to best fit as well.
If you put the anchors to the corners of the text box for both objects they should both scale with the parent panel/canvas.
The first text box is a header (one line) and the second is the body (multiple lines); their second one needs a lot more space to display.
And if I hadn't been answering on my phone I'd have probably spotted that 15k next to your name @Loius and not posted something so simple.
No problem :) That solution would've worked if I could guarantee they'd both be the same number of lines.