private void StamineStateChangedHandler(StaminaStates newState)
 {
     if (newState == StaminaStates.EXHAUSTED)
     {
         ResetSpeed();
     }
 }
 private void StamineStateChangedHandler(StaminaStates newState)
 {
     if (newState == StaminaStates.EXHAUSTED)
     {
         SetExhausted(true);
     }
     else
     {
         SetExhausted(false);
     }
 }
    private void DisplayState(StaminaStates newState)
    {
        if (StaminaStateText == null)
        {
            return;
        }
        switch (newState)
        {
        case StaminaStates.VIGOROUS: StaminaStateText.text = "Vigorous"; break;

        case StaminaStates.TIRED: StaminaStateText.text = "Tired"; break;

        case StaminaStates.EXHAUSTED: StaminaStateText.text = "Exhausted"; break;

        default: StaminaStateText.text = "N/A"; break;
        }
    }
    void Update()
    {
        if (_regenTimer > 0)
        {
            _regenTimer -= Time.deltaTime;
        }

        if (_regenTimer <= 0)
        {
            _currentStamina = Mathf.Clamp(_currentStamina + regenPerSecond * Time.deltaTime, 0, maxStamina);
        }

        float percentage = GetPercentageRemainingStamina();

        if (!_isExhausted)
        {
            if (percentage < percentageTired)
            {
                if (_currentState != StaminaStates.TIRED)
                {
                    _currentState = StaminaStates.TIRED;
                    if (StaminaStateChanged != null)
                    {
                        StaminaStateChanged(_currentState);
                    }
                }
            }
            else
            {
                if (_currentState != StaminaStates.VIGOROUS)
                {
                    _currentState = StaminaStates.VIGOROUS;
                    if (StaminaStateChanged != null)
                    {
                        StaminaStateChanged(_currentState);
                    }
                }
            }
        }
    }
    private void UseStamina(float amountUsed)
    {
        _regenTimer = timeBeforeRegen;

        if (_currentStamina > amountUsed)
        {
            _currentStamina -= amountUsed;
        }
        else
        {
            _currentStamina = 0;
            _isExhausted    = true;

            _currentState = StaminaStates.EXHAUSTED;
            if (StaminaStateChanged != null)
            {
                StaminaStateChanged(_currentState);
            }

            Invoke("RecoveredFromExhaustion", timeOfRestAfterExhaustion);
        }
    }