Often, there are pickups that the player can collect more than one of. In such situations, we can use an integer to represent the total number collected and use a UI Text object to display this total to the user. Let's modify this recipe to allow SpaceGirl to collect lots of stars!
Figure 3.10 – Example of collecting and displaying multiple items
To convert this recipe into one that shows the total number of stars that have been collected, do the following:
- Make three or four more copies of the star GameObject and spread them around the scene. This gives the player several stars to collect rather than just one.
Use the Ctrl + D (Windows) or Cmd + D (Mac) keyboard shortcut to quickly duplicate GameObjects.
- Change the contents of the C# PlayerInventory script class so that it contains the following:
using UnityEngine; public class PlayerInventory : MonoBehaviour { private PlayerInventoryDisplay...