Home > Mobile >  Localization for TextMeshPro in a Unity game
Localization for TextMeshPro in a Unity game

Time:05-20

I have several scripts to manage languages in my game, but the fact is that it's better to use TextMeshPro buttons than usual ones, the text itself is cooler and all this.

Though there is a problem, I need to get a component of my text and I can do it with usual Unity Text, but not with TMP:

private void ChangeText(string newText) => GetComponent<Text>().text = newText;

works ok, but I need to do it with GetComponent<TextMeshPro>().text [doesn't seem to exist] and I don't really understand how to get a TMP component out of a button.

CodePudding user response:

Firstly, make sure that you have actually imported TMPro at the start of your script:

using TMPro;

If you have already done that: the component you need is the TMP_Text:

GetComponent<TMP_Text>().text
  • Related