Each Pickup GameObject in the scene has a scripted component of the PickUp class. The PickUp object for each Pickup GameObject has a single property, a pickup type, which has to be one of the enumerated sets of Star, Key, or Heart. The use of an enumerated type means that the value has to be one of these three listed values, which means no misspelling/mistyping errors that could have happened with a general text string type can happen here, as in the previous recipe.
Previously, the PlayerInventory script class had two sets of responsibilities:
- Maintaining the internal record of items being carried.
- Detecting collisions, updating the state, and asking the display class to inform the player visually of the changed items being carried.
In this recipe, we separate these two sets of responsibilities into separate script classes:
- The InventoryManager script class will maintain the internal record of items being carried (and ask the display class to inform the player...