Пример #1
0
        //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);
            }
        }
Пример #2
0
 public ResourceStruct(int a, UIItemScript uiRef)
 {
     amount = a;
     UIItem = uiRef;
 }