Example #1
0
    public void Buy()
    {
        if (!Progress.CanAfford(offer))
        {
            AudioController.Instance.PlaySound("not_enough_money");
            return;
        }

        AudioController.Instance.PlaySound("cashier");

        Progress.Candy -= offer.price;

        switch (offer.offerType)
        {
        case OfferType.BuyBanana:
            Progress.ModAmmo(UsableType.Banana, 1);
            break;

        case OfferType.BuyDummy:
            Progress.ModAmmo(UsableType.Dummy, 1);
            break;

        case OfferType.BalloonUpgrade:
            Progress.UpgradeUsable(UsableType.Balloon);
            break;

        case OfferType.HouseUpgrade:
            Progress.UpgradeHouse();
            break;
        }

        if (!offer.singlePurchase)
        {
            return;
        }

        Progress.RemoveOffer(offer);
        if (offer.nextLevel == null)
        {
            Destroy(this.gameObject);
        }
        else
        {
            Progress.AddOffer(offer.nextLevel);
            offer = offer.nextLevel;
            UpdateDisplay();
        }
    }