Set the font of a TextMeshProUGUI component BY CODE
Hello Unity friends,
I would like to set the font of a TextMeshProUGUI
component (named unitName
below) by code, but I can't seem to do it. I tried two different ways and both failed.
1. Directly set it with
unitName.font = Resources.Load<TMP_FontAsset>("Fonts/DalelandsUncial-BOpn_SDF.asset");
This compiles fine but the font isn't applied during runtime. I have to drag it myself during runtime for the font to be changed at last.
2. Adding
unitName.LoadFontAsset();
or
unitName.UpdateFontAsset()
right afterwards, but the member function LoadFontAsset
is protected, and the other function didn't help either.
Help me please, I'm sure there's a way out for something as simple as that! :)
Your answer
Follow this Question
Related Questions
TextMesh Pro Warning: The character used for Ellipsis is not available in font asset 2 Answers
Get width of string using a font and fontsize 0 Answers
How to display Emojis using a Text Mesh 0 Answers
How do I get a BoxCollider2D to precisely fit to a TextMesh? 0 Answers
TextMeshpro arabic fonts stop displaying more than one word(last one) 1 Answer