C H A P T E R   12

images

Managing the Inventory

Having taken care of most of the preliminary setup for the inventory system, in this chapter you will move on to layout and overflow. The inventory will need to keep an array of all objects it currently contains. For that reason, it makes sense to put inventory-related scripts on the GameManager script.

To start, let's add an internal array to hold the objects. Because it will be constantly growing and shrinking, it needs to be a JavaScript type array.

  1. Open the Inventory scene from the book project.
  2. Open the GameManager script.
  3. Below the existing variables, add the following:
    //Dynamic array of objects ...

Get Beginning 3D Game Development with Unity: The World's Most Widely Used Multi-platform Game Engine 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.