Displaying multiple pickups of different objects as a list of text via a dynamic List<> of PickUp objects

When working with different kinds of pickups, one approach is to use a C# List to maintain a flexible-length data structure of 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 is how the text display of items is generated each time the inventory changes. We 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.

Getting ready

This recipe assumes that you are starting with the project ...

Get Unity 5.x Cookbook 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.