Game Development Reference
In-Depth Information
how MissionMgr searches for complete missions and rewards the player
using mechanics similar to those discussed earlier:
if (mt != null)
missionMgr.Add(mt);
10. The Insert() method of InventoryMgr is used to perform the actual in-
sertion work in the list of inventory objects. It is declared with the following
signature:
void Insert(InteractiveObj iObj){
}
11. This method first allocates a new InventoryItem with the new operator.
We have to use new instead of Object.Instantiate to create a new in-
stance of this class because this class does not inherit from Object . With a
new instance of InventoryItem available for use, we will populate its prop-
erties with the data from InteractiveObj , as shown in the following code:
InventoryItem ii = new InventoryItem();
ii.item = iObj.gameObject;
ii.quantity = 1;
12. Then, we will disable GameObject of InteractiveObj (just in case it is still
enabled), and finally add the InventoryItem to the list with a direct call to
inventoryObjects.add , as shown in the following code:
ii.item.SetActive (false);
inventoryObjects.Add (ii);
13. Lastly, just in case there is MissionToken attached to this GameObject
from some other code path, we will extract the token and add it to Mis-
sionMgr for tracking, as shown in the following code:
MissionToken mt =
ii.item.GetComponent<MissionToken>();
if (mt != null)
missionMgr.Add(mt);
Search WWH ::




Custom Search