Adding and implementing collectable objects
Typically, in a game, the player will be able to collect power-ups to increase their effectiveness, or to replace depleted life or energy.
In this game, our player will collect food to boost his health. This stage will involve adding a collectable and making the player react with a suitable animation sequence.
Instantiating the lunchBox collectable in the game level
Our first collectable is already set up as a prefab in the project files, making it easy to drag and drop into our game level without having to add components and set variables:
- In the Project panel, locate the
PACKT_Prefabs
folder. - Click to expand the
Pickups
subfolder and locate thelunchBox
prefab. - Drag
lunchBox
into the Hierarchy panel to instantiate it. - Position the prefab and navigate within the Scene view until it is clearly visible:
Inspecting the lunchBox collectable's components
The lunchBox
prefab is a game object with a few components attached. We will take a look and see how...