Game Development Reference
In-Depth Information
Figure 10.20
Score and ammo
counters
Creating Pickup Objects
Many video games have the player manage objects or resources as part of their gameplay.
You have already added ammo and health to your zombie game, but you will want the
player to be able to recharge these things. You can do this with some simple ammo and
health pickup objects.
1. If it is not already open, open your Unity project and scene.
2. Add two new cube objects to your scene with the Hierarchy view's Create menu or
import HealthPickup.fbx and AmmoPickup.fbx from the Chapter 10 online resources.
Make sure they have colliders attached to them. Switch the colliders attached to these
objects to triggers.
3. Go to the top of each of these object's Inspector views and pull down the Tags
list. Click Add Tag at the bottom of the list. In the new menu that appears in the
Inspector view, click the arrow next to Tags and add a new tag slot by adding a new
number to the Size variable. Add the tags Health and Ammo (Figure 10.21).
Figure 10.21
Adding custom tags
4. Create a new JavaScript file called PlayerCollisions.js in your Scripts folder and add
the following code to it. This script finds the variables in the player's FPS control-
ler and gun objects that control health and ammo, and then adds additional value
 
Search WWH ::




Custom Search