Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Unity's UI System | Unity UI and Sounds
Unity for Beginners
course content

Course Content

Unity for Beginners

Unity for Beginners

1. Unity Introduction
2. Write your First Script
3. Unity Physics
4. Unity UI and Sounds
5. Polishing and Export your Game

book
Unity's UI System

User Interface (UI) in Unity refers to the graphical elements that players interact with in a game or application. UI plays a critical role in guiding users through the experience, providing feedback, and enabling various actions.

Unity UI Essentials

Unity's UI system includes tools like Canvas for organizing elements, and components such as buttons, text fields, and images. These can be arranged and styled in Unity's editor.

Key Components

  • Canvas: The main container for UI elements;
  • Buttons: Clickable elements for actions;
  • Text Fields: Areas for text input/display;
  • Images: Visual elements for icons or backgrounds.

Getting Started

To add UI elements, go to the Hierarchy, right-click, and select 'UI'.

Creating UI in Unity

To create a UI in Unity, navigate to the Hierarchy, then press the left mouse button. After that, select UI.

We will have a list of all the UI elements that we can create, from text to image to buttons. We will discuss more about those elements and how to manipulate them in the next lessons. But now let’s take a small example of how to manipulate a text with script.

Manipulating text with script

Let’s select textMeshPro from that list.

A new text will be created for us in the game.

Note

If Unity asks you to implement TMP essentials please accept.

If we click on the text, all of its components will be shown in the inspector, and we can manipulate them manually.

Let’s add the test script to the object and write this code.

  1. Imports: The using statements at the top allow the script to access Unity's core functions and the TextMeshPro library, which is used for rendering text;

  2. Class Definition: public class test : MonoBehaviour defines a new class named test that inherits from MonoBehaviour, allowing it to be attached to GameObjects in Unity;

  3. Serialized Field: [SerializeField] TMP_Text myText; declares a field for a TextMeshPro text object. The [SerializeField] attribute makes this field visible in the Unity Editor, so you can assign a text object to it;

  4. Start Method: The Start() method is a Unity-specific function that runs once when the script is first enabled. Inside this method, myText.text = "test"; sets the text of the myText object to "test". When you play the game, this text will be displayed on the screen.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 1
We're sorry to hear that something went wrong. What happened?
some-alt