A reusable default canvas
Unity's UI canvas provides lots of options and parameters to accommodate the kinds of graphical layout flexibility that we have come to expect not only in games, but also from the web and mobile apps. With this flexibility comes additional complexity. To make our examples in this chapter easier, we'll first build a reusable prefab canvas that has our preferred default settings.
Create a new canvas and change its Render Mode to world space as follows:
- Navigate to GameObject | UI | Canvas.
- Rename the canvas as
DefaultCanvas
. - Set Render Mode to world space.
The Rect Transform component defines the grid system on the canvas itself, like the lines on a piece of graph paper. It is used for the placement of UI elements on the canvas. Set it to a convenient 640 x 480, with a 0.75 aspect ratio. The Rect Transform component's width and height are different from the world space size of the canvas in our scene. Let's configure the Rect Transform component using...