Session 4

Displaying the score

To display our score, we’re going to create a text object. Unity has a system called “Canvas” which can display user interface (UI) objects, such as text and menus with buttons.

Go to Create in the Hierarchy Window, and select UI, then Text. This will create three objects: The Canvas, a Text object parented to it, and an EventSystem object that catches button clicks.

We’re going to need two TextObjects, one for the score, and one for the GameOver text.

We’re going to create a GameManager object to track a few things throughout, starting with the score and the game over text. Create a new component, and rename it to “GameManager”. Then click Add Component, New Script, and then type “GameManager” as the name. In the script, replace everything with the following: