コード例 #1
0
    /// <summary>
    /// Activates a power-up.
    /// </summary>
    /// <param name="powerUp">Name of power-up to be activated.</param>
    /// <returns>If the power-up was activated.</returns>
    public bool ActivatePowerUp(string powerUp)
    {
        if (IsAnyActive() || playerController.inputBlocked)
        {
            return(false);
        }

        switch (powerUp)
        {
        case nameof(SpeedUp):
            SpeedUp = true;
            playerController.speedUp = true;
            powerUpDisplay.StartNewPowerUp(1);
            audioManager.PlaySound("Drinking");
            break;

        case nameof(SlowMotion):
            SlowMotion = true;
            TimeController.ChangeTime(slowMotionFactor);
            powerUpDisplay.StartNewPowerUp(2);
            audioManager.PlaySound("Drinking");
            break;

        case nameof(ShieldProtection):
            ShieldProtection = true;
            backpack.gameObject.SetActive(true);
            powerUpDisplay.StartNewPowerUp(0);
            audioManager.PlaySound("Zipper");
            break;

        default:
            return(false);
        }

        // Starts the coroutine that will wait a specified time to disable the power-up
        StartCoroutine(TimePowerUp(powerUp));

        return(true);
    }