User Interface (UI)

Learn Unity’s UI system to create interactive interfaces and enhance the player experience with buttons, text fields, images, and panels.

Introduction

In Unity, the UI system allows us to create UIs for our games and applications. Some common UI elements include buttons, text fields, images, and panels. To create a UI in Unity, we’ll use the Canvas object, which acts as the container for our UI elements.

UI elements are important for providing feedback to the player, displaying scores and other game state information, and allowing the player to interact with the game. Unity provides powerful tools for creating UI elements and integrating them into our game. Given below are the main components of the UI system in Unity.

The Canvas object

In Unity, UI elements are displayed on a special type of object called a Canvas. To create a Canvas object, go to the main menu and select “GameObject” > “UI” > “Canvas.” A new Canvas object will be created in the “Hierarchy” window. We could also right-click in the “Hierarchy” panel and select “UI” > “Canvas.”

Press + to interact
Creating a new Canvas object
Creating a new Canvas object

The Canvas object has several properties that control its behavior, such as the render mode (screen space, overlay, or world space), the sorting order, and the scaling mode. These properties determine how the Canvas object is displayed and how it interacts with other objects in the scene.

Adding UI elements

To add a UI element to the Canvas object, right-click the Canvas object in the “Hierarchy” window and select “UI” > the type of element we want to add. For example, to ...