0
0
Unityframework~20 mins

Text and TextMeshPro in Unity - Mini Project: Build & Apply

Choose your learning style9 modes available
Displaying Text with Text and TextMeshPro in Unity
📖 Scenario: You are creating a simple Unity scene where you want to display a welcome message to the player using two different text components: the built-in Text and the more advanced TextMeshPro.
🎯 Goal: Build a Unity script that sets the text of both a Text component and a TextMeshProUGUI component to show a welcome message.
📋 What You'll Learn
Create a public variable for a Text component
Create a public variable for a TextMeshProUGUI component
Assign the welcome message to both text components in the Start() method
Print the final messages to the Unity Console
💡 Why This Matters
🌍 Real World
Displaying text is essential in games and apps for instructions, scores, and messages. Unity's Text and TextMeshPro components are common tools for this.
💼 Career
Understanding how to use UI text components is a basic skill for Unity developers, useful in game development, interactive apps, and UI design.
Progress0 / 4 steps
1
Create public variables for Text components
Write a Unity C# script named WelcomeText. Inside the class, create two public variables: one called simpleText of type UnityEngine.UI.Text and another called tmpText of type TMPro.TextMeshProUGUI.
Unity
Need a hint?

Remember to include using UnityEngine.UI; for the Text component and using TMPro; for the TextMeshProUGUI component.

2
Create a welcome message string
Inside the WelcomeText class, create a private string variable called welcomeMessage and set it to "Welcome to Unity Text Demo!".
Unity
Need a hint?

Use private string welcomeMessage = "Welcome to Unity Text Demo!"; inside the class but outside any method.

3
Set the text components in Start()
Add a Start() method to the WelcomeText class. Inside it, set the text property of simpleText and tmpText to the welcomeMessage string.
Unity
Need a hint?

Use the Start() method to set both simpleText.text and tmpText.text to the welcomeMessage.

4
Print the welcome messages to the Console
Inside the Start() method, after setting the text properties, add two Debug.Log() statements to print the values of simpleText.text and tmpText.text.
Unity
Need a hint?

Use Debug.Log() to print the text values after setting them.