Displaying multiple pickups of different objects as a list of text via a dynamic List<> of scripted PickUp objects
When working with different kinds of pickups, one approach is to use a C# List to maintain a flexible-length data structure containing the items currently in the inventory. In this recipe, we will show you how, each time an item is picked up, a new object is added to such a List
collection. An iteration through the List
will show how the text display for items is generated each time the inventory changes.
Here, we will introduce a very simple PickUp
script class, demonstrating how information about a pickup can be stored in a scripted component, extracted upon collision, and stored in our List
:
Figure 3.29: Example of the UI displaying multiple pickups of different objects
Getting ready
This recipe assumes that you are starting with the Simple2Dgame_SpaceGirl
project, which we set up in the first recipe of this chapter.