//Adds a resource to the dictionary, and to the UI public void AddResource(int resourceType, int pickedUpAmount, Sprite graphics) { if (resourcesDict.ContainsKey(resourceType)) { //update the dictionary key int newAmount = resourcesDict[resourceType].amount + pickedUpAmount; resourcesDict[resourceType].UIItem.ShowNumber(newAmount); resourcesDict[resourceType].amount = newAmount; } else { //create the UIItemScript and display the icon UIItemScript newUIItem = Instantiate <GameObject>(resourceItemPrefab).GetComponent <UIItemScript>(); newUIItem.transform.SetParent(inventory, false); resourcesDict.Add(resourceType, new ResourceStruct(pickedUpAmount, newUIItem)); resourcesDict[resourceType].UIItem.ShowNumber(pickedUpAmount); resourcesDict[resourceType].UIItem.DisplayIcon(graphics); } }
public ResourceStruct(int a, UIItemScript uiRef) { amount = a; UIItem = uiRef; }