Exemple #1
0
    public void PurchaseItem(ShopItem item)
    {
        string itemName = item.GetName();
        int    cost     = item.GetCost();

        if (cost <= PlayerDataController.Instance.Data.Money)
        {
            //change and write data
            PlayerDataController.Instance.AddMoney(-cost);
            PlayerDataController.Instance.ItemPurchased(item.GetItemId());
            PlayerDataController.Instance.WriteData();
            //set new money text
            MoneyText.text = PlayerDataController.Instance.Data.Money.ToString();
            //play animation and other do other processing
            item.BuyItem();
        }
        else
        {
            item.AnimateError();
        }
    }