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!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Real-time Group Chat using Firebase Realtime Database

Expose Kubernetes cluster resources

How to Randomize a Collection in Wix without Velo Code using Python and Selenium

Wax Guild Candidacy Announcement  —  BlokCrafters

Learning To Write Better Python Code

Software Diversity: Divided We Win

Fix ‘No WiFi Adapter Found’ Ubuntu 20.04

CUE Development Update — 10th May 2021

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
Justen Chong

Justen Chong

More from Medium

Tiling a Procedurally Generated Unity TileMap

Unity: Create your own Wordle in under 24 hours

A Series On Creating Immersive Audio in Unity with Custom Wwise Scripts

Magnetism in Unity Made Easy!