Wiring up the controller with the UI

Returning to Unity, we need to tell the component about our Step Text UI element.

  1. Select Game Controller in Hierarchy.
  2. Locate the Step Text object (Main Canvas/ Nav Panel/ Step Text) and drag it onto the Step Text slot of the Instructions Controller.

If you press Play in Unity now, the nav bar text should read Step 0 (instead of Step #).

Now let's wire up the buttons to our controller:

  1. In Hierarchy, select the Next Button (Instruction Canvas/ Nav Panel/ Next Button).
  2. In Inspector, press + in On Click() to add a new click event response.
  3. Drag the Game Controller onto the empty object slot.
  4. In its function select list, locate and select the NextStep() function, as shown ahead:
  1. Following similar steps for the Previous Button, add a click event response, drag Game Controller, and select PreviousStep().

Save your work and press Play. Now when you click the Next and Previous buttons (in the Game window not the Scene one!), the step text is updated with the counter value! Simple, yet satisfying. The title and body text don't update yet, we'll work on that next.

Also notice that if you keep pressing Previous, the step number can go negative. We'll fix that too.

..................Content has been hidden....................

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