Displaying the Score in Unity Using TMP

There really is no reason to use the standard Unity UI text over TMP (TextMeshPro). TextMeshPro has a ton of features that you can use to elevate the look of your text, which we can cover another time.

In order to use TMP make sure you import the correct library at the top of your code.

using TMPro;

When using TMP make sure you declare the correct data type for what you’re using otherwise you’ll have a headache. Since we’ll be using text on the UI we’ll need to declare “TextMeshProUGUI”

If you wanted to use TMP as an object in the scene then you would declare a TextMeshPro class.

We Serialize the object so that we can set it in the Inspector from the Hierarchy. Code wise, we can access the text using the TextMeshProUGUI.text syntax. So in my case, we can update the message of the text object like so:

You can set the text to any string you want and it will update on your screen in the Game view! Done!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store