Game Development Reference
In-Depth Information
Implementing the InventoryMgr script
The InventoryMgr class contains the system that manages the Interact-
iveObj classes that the player collects. It displays inventory items in an inventory
panel at the bottom of the screen. It has a method for adding inventory items and
displaying inventory at the bottom of the screen. Perform the following steps to im-
plement the InventoryMgr script:
1. To begin, recall that the class declaration for this system follows the same
pattern as the others that were created with the new script wizard. Until this
point, however, we haven't included any other namespaces than the default
two: UnityEngine and System.Collections . For this class, note that
we add using System.Collections.Generic in the code. Doing this
gives us access to the List<> datatype in our scripts, which we will need to
store the collection of inventory objects, as shown in the following code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class InventoryMgr : MonoBehaviour
{
public List<InventoryItem>
inventoryObjects = new
List<InventoryItem>();
2. The InventoryMgr class also has parameters that describe the way in
which the constraints on the UI will be displayed, along with a reference to
the MissionMgr script, as shown in the following code:
public int numCells;
public float height;
public float width;
public float yPosition;
private MissionMgr missionMgr;
Search WWH ::




Custom Search