Understanding the Canvas and RectTransform
We are only going to focus on the in-game UI to communicate different information to the player using the Unity GUI system (or uGUI). At the time of writing this book, a new GUI system called UI Toolkit has been released, but uGUI will still be here for a while, given UI Toolkit will be used mostly in new projects, and is still perfectly capable of handling all types of UI. We will explore UI Toolkit in the next chapter.
If you are going to work with Unity UI, you first need to understand its two main concepts—the Canvas and RectTransform. The Canvas is the master object that will contain and render our UI, and RectTransform is the feature in charge of positioning and adapting each UI element on our screen.
In this section, we will be:
- Creating a UI with the Canvas
- Positioning elements with RectTransform
Let’s start by using the Canvas component to create our UI.