Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Localization for TextMeshPro in a Unity game

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading