Text and TextMeshPro let you show words on the screen in your game or app. They help make your messages clear and nice to look at.
0
0
Text and TextMeshPro in Unity
Introduction
When you want to show a score or timer in a game.
When you need to display instructions or menus.
When you want to add labels to buttons or objects.
When you want text that looks sharp and can be styled easily.
When you want to support multiple languages with good text rendering.
Syntax
Unity
using UnityEngine; using TMPro; public class ShowText : MonoBehaviour { public Text uiText; // For UI Text component public TextMeshProUGUI tmpText; // For TextMeshPro UI component void Start() { uiText.text = "Hello World!"; tmpText.text = "Hello TextMeshPro!"; } }
Text is the older Unity UI text component, simpler but less flexible.
TextMeshPro is newer, sharper, and supports more styling options.
Examples
Set the text of a UI Text component to show a score.
Unity
uiText.text = "Score: 100";Set the text of a TextMeshProUGUI component to show a message.
Unity
tmpText.text = "Game Over!";Change the color of TextMeshPro text to red.
Unity
tmpText.color = Color.red;
Change the font size of UI Text to 24 points.
Unity
uiText.fontSize = 24;Sample Program
This script sets a TextMeshProUGUI text to say "Welcome to the game!" in green color and large font size when the game starts.
Unity
using UnityEngine; using TMPro; public class TextExample : MonoBehaviour { public TextMeshProUGUI messageText; void Start() { messageText.text = "Welcome to the game!"; messageText.color = Color.green; messageText.fontSize = 36; } }
OutputSuccess
Important Notes
TextMeshPro uses signed distance field rendering for sharp text at any size.
Always use TextMeshPro for better quality and more features in modern Unity projects.
Remember to add the TextMeshPro package via Unity Package Manager if not already included.
Summary
Text and TextMeshPro display text on screen in Unity.
TextMeshPro offers better quality and styling than the older Text component.
Use TextMeshPro for modern, clear, and flexible text in your games or apps.