In this recipe, you created a UI Text GameObject called Text-carrying-star to display a text message stating whether the player is carrying a star. You created two script classes, and an instance of each was added as components of the player's player-SpaceGirl character GameObject:
- The PlayerInventory script class detects player-star collisions, updates internal variables stating whether a star is being carried, and asks for the UI display to be updated each time a collision is detected.
- The PlayerInventoryDisplay script class handles communication with the user by updating the text message that's displayed by the Text-carrying-star UI Text GameObject.
A game design pattern (best practice approach) called the Model-View-Controller (MVC) pattern separates the code that updates the UI from the code that changes player and game variables, such as score and inventory item lists. Although this recipe has only one variable and...