private void Awake() { selectedItemScript = GameObject.Find("SelectedItems").GetComponent <UIItemScript>(); tooltipScript = GameObject.Find("Tooltip").GetComponent <TooltipScript>(); spriteImage = GetComponent <Image>(); UpdateItemFunction(null); }
//Adds a resource to the dictionary, and to the UI public void AddResource(string 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; }