Creating a UI canvas and button

In Unity, user interface (UI) buttons reside on a canvas. Create a canvas:

  1. In Hierarchy, select Create | UI | Canvas.
  2. Select Canvas and change UI Scale Mode to Constant Physical Size.

By default, the Canvas UI Scale Mode is set to Constant Pixel Size. This is an issue since mobile devices can have many different screen sizes and density (DPI), and your buttons will get smaller or bigger depending on the screen size. We will change it to Constant Physical Size.

You can then arrange your UI on the canvas as you desire. Create and position a button in the lower right-hand corner of the screen.

  1. With the Canvas selected, right-click on UI | Button.

The button is easily previewed in the Game window. In Inspector, note the Anchor Presets icon in the upper-left corner of Rect Transform for the button.

  1. Press the Anchor Presets icon to open the presets dialog box.

At this point, you can set the anchor with a mouse click or set both the anchor and pivot using shift+click. Or, you can set the anchor and pivot and position using Alt+Shift+click the mouse. We will do that:

  1. Press Alt+Shift on the keyboard and then click on the icon on the Bottom-Right corner:

Our button should now be in the lower right corner in the Game view too.

  1. In Hierarchy, unfold Button and select Text. Change Text to say Slow, as shown in the following screenshot:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset