- Home /
TextMeshPro Array
Hi I'm making in game menu elements with unity's ui elements but of course texts are looking bad. Anyway, I put a textmeshpro's text but in the coding, I'm not getting an array to edit ui's features (getting tags to edit like color or fonts etc.). So how can I use array like in example code for textmeshpro
_inventory_Texts = GameObject.FindGameObjectsWithTag("Inventory_Text");
foreach (GameObject r in _inventory_Texts)
{
Text b = r.GetComponent<Text>();
b.fontSize = 20;
b.color = Color.white;
b.font = (Font)Resources.Load("libel-suit-rg");
RectTransform a = r.GetComponent<RectTransform>();
a.offsetMin += new Vector2(60, -60);
}
Answer by ransomink · Jan 10, 2021 at 02:41 AM
Inside your foreach loop, you get the Text
component: this is Unity's UI Text component, not Text Mesh Pro's. First, make sure you have using TMPro;
to access any Text Mesh Pro class and get the correct component. UI is TextMeshProUGUI
; 3D is TextMeshPro
.
"Text$$anonymous$$eshProUGUI" I missed this class to use. I was confused. Thanks
Your answer
Follow this Question
Related Questions
How can I get access default library in code 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Initialising List array for use in a custom Editor 1 Answer
Passing a variable to Start() - C# 2 Answers