IEnumerator LerpHUDValues(HUD_Model.PowerTypes powerType, float targetValue) { bool lerpDone = false; float maxValueBasedOnType = powerType == HUD_Model.PowerTypes.POWER_ENERGY ? _hudModel.maxEnergy : _hudModel.maxFuel; float endValue = targetValue / maxValueBasedOnType; while (!lerpDone) { if (powerType == HUD_Model.PowerTypes.POWER_ENERGY) { _energyFiller.fillAmount = Mathf.Lerp(_energyFiller.fillAmount, endValue, Time.deltaTime * _hudModel.updateHudSmoothMultiplier); } else { _fuelFiller.fillAmount = Mathf.Lerp(_fuelFiller.fillAmount, endValue, Time.deltaTime * _hudModel.updateHudSmoothMultiplier); } float typeValue = powerType == HUD_Model.PowerTypes.POWER_ENERGY ? _energyFiller.fillAmount : _fuelFiller.fillAmount; if (nearlyEqual(typeValue, endValue, _minimumAcceptedFloatValue)) { lerpDone = true; } yield return(null); } }
void UpdateHUD(HUD_Model.PowerTypes powerType, float targetValue, bool stopCoroutine = false) { if (stopCoroutine) { StopAllCoroutines(); /// that means the player died. _energyFiller.fillAmount = 0; } else { StartCoroutine(LerpHUDValues(powerType, targetValue)); } }