CodeBlanks Logo Icon CodeBlanks

Text and TMP

Learn to display text with Text and TextMeshPro.

Text and TextMeshPro (TMP)

The modern standard for displaying text on screen in Unity is the TextMeshPro (TMP) component. Replacing legacy UI Text, TMP utilizes SDF (Signed Distance Field) technology to keep glyphs razor-sharp across all resolutions.

// Modifying TextMeshProUGUI text content
using TMPro;
public TextMeshProUGUI scoreText;
scoreText.text = "Score: 100";

When text is scaled up or approached by a camera, classic pixelation and blurring are eliminated.

Text properties and Font Asset

TextMeshPro hosts rich styling fields such as fontSize, color, and alignment. TTF or OTF font files in Unity are first converted into a dedicated TMP Font Asset.

scoreText.fontSize = 36;
scoreText.color = Color.yellow;

This enables instantaneous GPU-accelerated drop shadows, outlines, and glow effects.

Practice Print TMP component and text

Assign "TextMeshProUGUI" to component and "Score: 100" to displayText. Print Component: TextMeshProUGUI | Text: Score: 100 to the console.

Starter code

Player.cs
using System;

class Program
{
    static void Main()
    {
        // component ve displayText değerlerini tanımlayıp yazdır
    }
}

Sample solution

Player.cs
using System;

class Program
{
    static void Main()
    {
        string component = "TextMeshProUGUI";
        string displayText = "Score: 100";
        Console.WriteLine("Component: " + component + " | Text: " + displayText);
    }
}

Expected output

Component: TextMeshProUGUI | Text: Score: 100

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the most prominent advantage of TextMeshPro (TMP) over legacy UI Text?

  • Only supporting black and white colors
  • Remaining smooth and crisp at high resolutions via SDF technology Correct answer
  • Automatically computing 3D physics collisions
  • Transcribing audio files directly into text

Explanation: TextMeshPro provides vector-like sharpness at any size through its SDF (Signed Distance Field) font technology.

2 Update text content

Question
scoreText.____ = "Health: 100";
Answer
scoreText.text = "Health: 100";

Explanation: The 'text' property is used to modify the displayed string on a TextMeshPro component.

3 TMP text concepts

Term Meaning
TextMeshProUGUI TMP renders high-quality text on Canvas
fontSize Sets text size in points
SDF Keeps text sharp at all scales
Font Asset TMP font asset from font files

All lessons in Intermediate