public IEnumerator ClickMethod(Buyable toDisplay)
    {
        parent.Hide();
        yield return(toDisplay.Buy());

        parent.Destroy();
    }
Esempio n. 2
0
    public virtual void Buy(int index)
    {
        InputModeDisplay.instance.CloseConfirmation();
        GameplayManager gm = GameplayManager.instance;

        if (index < piles.Count &&
            CanBuy(index))
        {
            switch (costType)
            {
            case Store.Type.attack:
                gm.attack -= piles[index].price;
                break;

            case Store.Type.coin:
                gm.coin -= piles[index].price;
                break;

            case Store.Type.hammers:
                gm.hammers -= piles[index].price;
                break;

            case Store.Type.science:
                gm.science -= piles[index].price;
                break;
            }
            Buyable    bought = piles[index].elements[0];
            StoreEntry entry  = piles[index];
            entry.price  = piles[index].basePrice;
            piles[index] = entry;
            RemoveElement(bought);
            GameplayManager.instance.StartCoroutine(bought.Buy());
        }
        else if (partialBuy &&
                 index < piles.Count)
        {
            switch (costType)
            {
            case Store.Type.attack:
            {
                StoreEntry entry = piles[index];
                entry.price -= gm.attack;
                piles[index] = entry;
                gm.attack    = 0;
                break;
            }

            case Store.Type.coin:
            {
                StoreEntry entry = piles[index];
                entry.price -= gm.coin;
                piles[index] = entry;
                gm.coin      = 0;
                break;
            }

            case Store.Type.hammers:
            {
                StoreEntry entry = piles[index];
                entry.price -= gm.hammers;
                piles[index] = entry;
                gm.hammers   = 0;
                break;
            }

            case Store.Type.science:
            {
                StoreEntry entry = piles[index];
                entry.price -= gm.science;
                piles[index] = entry;
                gm.science   = 0;
                break;
            }
            }
        }
    }