Adding the scoring UI components

The upper-right corner of our game's interface and canvas, will contain the scoring information. This section demonstrates how to create the necessary UI components: 

  1. Right-click the HUD_Canvas GameObject in the Hierarchy panel and select UIText. We will use this text object for our score label.
  2. Rename the text component as Score_Label
  3. In the Inspector panel, change the Text value of the Text (Script) component to Score.
  4. In the Text (Script) component, make the following changes or select other settings as you wish. You can experiment with the game in game mode to see how this will look during the game:
    • Font Style: Bold
    • Font Size: 16
    • Color: Dark Blue
  5. Either in the Inspector panel or in Scene view, resize the rectangle encasing your Score_Label UI text component so that there is no excessive blank space above, below, or to the right of the text.

 

  1. Right-click the HUD_Canvas GameObject in the Hierarchy panel and select UIText. We will use this text object to display the current score.
  2. Rename the text component as Score_Value
  3. In the Inspector panel, change the Text value of the Text (Script) component to 000000000. This will help us determine the layout.
  4. Either in the Inspector panel or in Scene view, resize the rectangle encasing your Score_Value UI text component so that there is no excessive blank space above, below, or to the right of the text.
  5. Repeat step 4 for the Score_Value text component.

Now that you have the two score-related UI text components have been added to your canvas, you are ready to reposition them on the screen.

  1. In the Scene view, adjust the Score_Label and Score_Value text objects so that their rect transform is sized to encase the text values
  2. Lastly, reposition the two text objects in Scene view so that they are aligned with each other in the top-right corner of the canvas

Your finished work should look similar to the following screenshot from the Game view.

Make any necessary adjustments before moving on to the next section.

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

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