Adding points based on cherry collection and combat hits
In this section, we will edit the appropriate scripts so that the Cucumber Man can earn points, related to cherries, based on the following criteria:
In-game event | Points |
Cucumber Man picks cherry | + 5 |
Cucumber Man hits beetle with cherry | + 10 |
Creating a points manager script
In this section, we will create and edit a script to manage our points and to display them on our game's HUD. Here are the steps:
- In the
Hierarchypanel, select theHUD_Canvas|Score_Value - In the
Inspectorpanel, click theAdd Componentbutton - Select
New Scriptand name the scriptPointsManager - In the
Projectpanel, clickFavorites|All Scripts - Drag the
PointsManagerscript to theAssets|Custom Scriptsfolder - Double-click the
PointsManagerscript to open it in an editor - Edit the script so that it matches the following code
The first section of the code contains the namespace import statements and the PointsManager class declaration:
using System.Collections; using System.Collections...