I have make a shop system which can fill a list of scriptable object(ShopItem) to a shop slot prefab, which than clone itself with the data of different shop items.
But when it comes to the buy button, I don’t know how to reference the separate value of a item from the shop list. The buy button now reduce the combine value of all items on the list.
public class BuyButton : MonoBehaviour
{
public int itemID;
public void BuyItem()
{
for (int i = 0; i < Shop.shop.shopItemList.Count; i++)
{
if (GameManager.gameManager.CheckMoney(Shop.shop.shopItemList[i].value))
{
GameManager.gameManager.ReduceMoney(Shop.shop.shopItemList[i].value);
}
}
}
}
public void ReduceMoney(float amount)
{
money -= amount;
UpdateUI();
}
public bool CheckMoney(float amount)
{
if (amount <= money)
{
return true;
}
return false;
}