public bool Add(Resources item, int num) { reader = GetComponent <inventoryReaderV2>(); inventoryItems resurce = new inventoryItems(); resurce.item = item; resurce.amount += num; if (Bag.Count <= 0) { Bag.Add(resurce); reader.currentWeight += resurce.item.weight; return(true); } if (Bag.Count > 0) { for (int i = 0; i < Bag.Count; i++) { if (Bag[i].item.typeOfResource == resurce.item.typeOfResource) { Bag[i].amount += num; reader.currentWeight += resurce.item.weight; return(true); } if (i == Bag.Count - 1 && Bag[i].item.typeOfResource != resurce.item.typeOfResource) { Bag.Add(resurce); reader.currentWeight += resurce.item.weight; return(true); } } } return(false); }
void Start() { inventoryScript = GameObject.FindGameObjectWithTag("Inventory").GetComponent <inventoryReaderV2>(); }