Writing the Player Inventory

In this next section, we will establish a script for the player that stores information on what the player has collected in the game. During the game we are creating, the player will need to collect power cells to power the door, and a box of matches to light a campfire.

The player is the best object upon which to store this information, as it will allow other objects to query this Inventory script for information—for example, later we will add a 3D model of a generator, which will display the current charge state of the door based upon information in this script.

Select the Scripts folder in the Project panel and click the Create button, then choose the relevant scripting language you have been working in. Rename your ...

Get Unity 3.x Game Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.