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 new script Inventory, and launch it in the script editor.
Saving the charge value
As we are establishing an inventory of collected items, we should make particular values of the inventory available to all scripts. The amount of power cells collected...