コード例 #1
0
 IEnumerator drainCoins()//drains the player's coins into the tree as the button is held down
 {
     while (ButtonLetGo == false)
     {
         if (coinScript.getCurrentCoins() > 0)                           //while the player still has some coins
         {
             int CoinsToDrain = 1 + (coinScript.getCurrentCoins() / 10); //drains coins faster for every 10 coins the player has
             coinScript.spendCoins(CoinsToDrain);                        //takes the coins away from the player
             updateCoinBar(CoinsToDrain);                                //added coins add to coin goal and update coin bar
             giveCoinsToTree(CoinsToDrain);                              //added coins are given to the tree
         }
         yield return(new WaitForSeconds(0.2f));
     }
 }
コード例 #2
0
    public void buySeed()                                                       //the function that handles buying a seed
    {
        if (coinScript.getCurrentCoins() >= currentPlant.Price)                 //if the player has enough coins to buy a new seed
        {
            if (seedHandlerScript.seedCheck())                                  //if already holding a seed that hasn't been planted, refund it
            {
                coinScript.gainCoins(seedHandlerScript.whatSeedIsHeld().Price); //find how much coins to refund and give it back to the player
            }

            coinScript.spendCoins(currentPlant.getPrice()); //spends coins to buy new seed
            seedHandlerScript.holdSeed(currentPlant);       //puts new seed in hand
            uiControler.closeAll();                         //closes all panels so the player can plant the new seed
        }
    }
コード例 #3
0
    public Plant plantSeed()//returns the current seed held and buys a new one if possible, otherwise empties hand
    {
        Plant Sprout = CurrentSeedHeld;

        if (CurrentSeedHeld.Price > coinScript.getCurrentCoins())//if you can't afford a new seed, empty hand. Otherwise autobuys a new seed for easy planting
        {
            //hides held seed graphics and empties hand
            CurrentSeedHeld = null;
            HeldSeedDisplay.SetActive(false);
            HoldingSeed = false;
        }
        else
        {
            coinScript.spendCoins(CurrentSeedHeld.Price);//buys a new seed of the current plant
        }

        return(Sprout);
    }