December 2014
Beginner
384 pages
11h 15m
English
Next, we will need to create a few scripts to hook the player up to the HUD elements, so when we take damage or collect coins in the level, they will update accordingly.
Let’s first add a script to the hud_sprite display so that we can add to the total when we collect coins. This will be slightly different from anything we have learned yet, as we are counting up but displaying the results using sprites.
1. Create a new script and call it “CoinCounter.” Place it inside the GUI folder of our _scripts folder, just for organizational reasons.
2. With the script selected, drag it and attach it to the hud_sprite element in the Scene or Hierarchy.
3. Double-click to open it and adjust the contents to match Listing 10.5.
Listing ...