コード例 #1
0
    //forward call to the PowerUpManager
    //activate passive powerup selection
    public bool ActivatePassivePowerUp()
    {
        if (!IsPassivePowerUpSelected())
        {
            return(false);
        }
        PassivePowerUp powerup = GetPassivePowerUp();

        bool affordable = true;

        //loop through resources
        for (int i = 0; i < GameHandler.resources.Length; i++)
        {
            //check if we can afford buying this powerup
            if (GameHandler.resources[i] < powerup.cost[i])
            {
                affordable = false;
                break;
            }
        }
        if (!affordable)
        {
            return(false);
        }

        //affordable is true, substract resources
        for (int i = 0; i < powerup.cost.Length; i++)
        {
            GameHandler.resources[i] -= powerup.cost[i];
        }
        //activate powerup
        powerUpScript.ActivatePassive();
        return(true);
    }