private void PopulateShop() { for (int i = 0; i < shopItems.Length; i++) { ShopItemsPreset item = shopItems[i]; GameObject itemObject = Instantiate(shopItemPrefab, slotsParent); itemObject.GetComponent <Button>().onClick.AddListener(() => OnButtonClick(item)); itemObject.transform.GetChild(0).GetComponent <Image>().sprite = item.itemMinature; itemObject.transform.GetChild(1).GetComponent <Text>().text = item.itemName; itemObject.transform.GetChild(2).GetComponent <Text>().text = item.cost.ToString(); } }
private void OnButtonClick(ShopItemsPreset item) { Debug.Log(item.itemName); if (money >= item.cost) { money = money - item.cost; PlayerPrefs.SetInt("money", money); if (item.itemName.Equals("Stan")) { int i = PlayerPrefs.GetInt("Stan"); i++; PlayerPrefs.SetInt("Stan", i); } if (item.itemName.Equals("Kayle")) { int i = PlayerPrefs.GetInt("Kayle"); i++; PlayerPrefs.SetInt("Kayle", i); } } }