Making your first Unity project helps you learn how to create and run a simple game scene. It shows you how to display text on the screen, like saying "Hello World" to start.
First Unity project (Hello World scene)
1. Create a new Unity project. 2. In the Hierarchy, create a UI Text object: GameObject > UI > Text - TextMeshPro. 3. Create a new C# script and attach it to a GameObject. 4. In the script, use: using TMPro; using UnityEngine; public class HelloWorld : MonoBehaviour { public TMP_Text helloText; void Start() { helloText.text = "Hello World!"; } }
You need to have TextMeshPro package installed (usually included by default).
Attach the script to any GameObject in the scene and link the TextMeshPro UI text in the Inspector.
using TMPro; using UnityEngine; public class HelloWorld : MonoBehaviour { public TMP_Text helloText; void Start() { helloText.text = "Hello World!"; } }
// Alternative: Using UnityEngine.UI.Text (older UI system) using UnityEngine; using UnityEngine.UI; public class HelloWorld : MonoBehaviour { public Text helloText; void Start() { helloText.text = "Hello World!"; } }
This complete example shows how to set up a simple Unity scene that displays "Hello World!" using a TextMeshPro UI text and a script.
// HelloWorld.cs using TMPro; using UnityEngine; public class HelloWorld : MonoBehaviour { public TMP_Text helloText; void Start() { helloText.text = "Hello World!"; } } // Steps to run: // 1. Create a new Unity project. // 2. Add a Canvas to the scene (if not present). // 3. Add a TextMeshPro - Text object to the Canvas. // 4. Create this HelloWorld script and attach it to an empty GameObject. // 5. Drag the TextMeshPro text object to the 'helloText' field in the Inspector. // 6. Press Play to see "Hello World!" on the screen.
Make sure to import TextMeshPro essentials if prompted by Unity.
UI elements like TextMeshPro need a Canvas in the scene to be visible.
You can customize the font size, color, and position of the text in the Inspector.
Creating a first Unity project helps you understand scenes, UI, and scripting basics.
Use a TextMeshPro UI text to show messages like "Hello World!" on screen.
Attach scripts to GameObjects and link UI elements to control what they show.
Practice
Hello World scene in your first Unity project?Solution
Step 1: Understand the goal of a first Unity project
The first project is usually simple to help beginners learn the basics of scenes and UI.Step 2: Identify what a Hello World scene does
It shows a simple message like "Hello World!" on screen to confirm everything works.Final Answer:
To display a simple message on the screen and learn basic Unity setup -> Option AQuick Check:
First project = simple message display [OK]
- Thinking Hello World is a full game
- Confusing UI design with 3D modeling
- Trying to write shaders too early
Solution
Step 1: Recall correct syntax for assigning string in C#
Strings must be in double quotes and assigned with = operator.Step 2: Check TextMeshPro property usage
The correct property to change text is .text, sotextMeshProUGUI.text = "Hello World!";is correct.Final Answer:
textMeshProUGUI.text = "Hello World!"; -> Option CQuick Check:
Assign string with .text and double quotes [OK]
- Using single quotes for strings in C#
- Missing quotes around Hello World!
- Using a non-existent setText method
using TMPro;
using UnityEngine;
public class HelloWorld : MonoBehaviour {
public TextMeshProUGUI messageText;
void Start() {
messageText.text = "Hello World!";
}
}What will appear on the screen when you run the scene?
Solution
Step 1: Understand the Start() method in Unity
Start() runs once when the scene starts, so the text assignment happens immediately.Step 2: Check the text assignment
The script sets messageText.text to "Hello World!", so that exact text will show on the UI.Final Answer:
The text "Hello World!" will appear on the UI -> Option DQuick Check:
Start() sets text to "Hello World!" [OK]
- Thinking Start() does not run automatically
- Confusing variable name with displayed text
- Assuming compile error without checking code
using TMPro;
using UnityEngine;
public class HelloWorld : MonoBehaviour {
public TextMeshProUGUI messageText;
void Start() {
messageText.text = "Hello World!";
}
}What is the most likely reason the text is not showing?
Solution
Step 1: Check common reasons for UI text not updating
If the public field is not linked in Inspector, messageText is null and text won't show.Step 2: Verify code correctness
The code syntax is correct, Start() is spelled right, and variable privacy does not affect linking.Final Answer:
The TextMeshProUGUI field is not linked to the UI text in the Inspector -> Option BQuick Check:
Unlinked UI field = no text shown [OK]
- Assuming syntax errors without checking code
- Thinking private variables must be used
- Ignoring Inspector linking step
Solution
Step 1: Understand how button clicks trigger actions
Unity buttons use OnClick events to call public methods in scripts.Step 2: Identify correct way to change UI text on click
Write a public method that sets the TextMeshProUGUI text to "Welcome!" and link it to the button's OnClick.Final Answer:
Create a public method in a script that sets the TextMeshProUGUI text, then link this method to the button's OnClick event -> Option AQuick Check:
Button OnClick calls public method to change text [OK]
- Expecting Start() to handle button clicks
- Changing button text instead of target text
- Using Update() unnecessarily causing performance issues
Ready to prove it?
Pass the test and this pattern moves unknown
