public void BuyItem() //On click event { if (itemID == 0) { Debug.Log("Error: No weapon ID set"); //shouldnt see this. return; } for (int i = 0; i < ItemShop.itemShop.itemList.Count; i++) { if (ItemShop.itemShop.itemList[i].ItemID == itemID /*&& !ItemShop.itemShop.itemList[i].bought*/ && GameManager.gameManager.CheckMoney(ItemShop.itemShop.itemList[i].ItemPrice) && PersistentDataManager.GetItemAmount(i) < 5) { //We can buy item if hasnt been bought, have enough $$, and has same ID in the list. ItemShop.itemShop.itemList[i].bought = true; GameManager.gameManager.SubtractMoney(ItemShop.itemShop.itemList[i].ItemPrice); FindObjectOfType <AudioManager>().Play("CashBell"); UpdateBuyButton(); //item index = i, thus the save index for persistentdatamanager = i+itemstart; PersistentDataManager.PurchaseItem(i); ItemShop.itemShop.UpdateItemAmount(i + 1); } //if they do not have enough gold. else if (ItemShop.itemShop.itemList[i].ItemID == itemID && !ItemShop.itemShop.itemList[i].bought && !GameManager.gameManager.CheckMoney(ItemShop.itemShop.itemList[i].ItemPrice)) { NotEnoughGoldWindow.SetActive(true); Debug.Log("NO Enough money"); } else if (ItemShop.itemShop.itemList[i].ItemID == itemID && ItemShop.itemShop.itemList[i].bought) { Debug.Log("Has been bought"); } } ItemShop.itemShop.UpdateSprite(itemID); }