How it works...k
In the script class PlayerInventory, the variable inventory is a C# List<>. This is a flexible data structure that can be sorted, searched, and dynamically (at runtime, when the game is being played) have items added to and removed from it. The <PickUp> in pointy brackets means that variable inventory will contain a list of PickUp objects. For this recipe, our PickUp class just has a single field, a string description, but we'll add more sophisticated data items in PickUp classes in later recipes. This variable inventory is initialized to be a new, empty C# List of PickUp objects.
Before the scene starts, the Awake() method of script class Player caches a reference to the PlayerInventoryDisplay scripted component.
When the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access