private void EntityStats_OnHealthReplenish(object sender, System.EventArgs e) { for (int i = 0; i < healthBarList.Count; i++) { holdingData = healthBarList[i]; holdingData.sliderTimer = holdingData.sliderBarDeplenishTimer; healthBarList[i] = holdingData; SetBarPercentage(healthBarList[i], EntityStats.Instance.GetNormalisedHealthOfEntity(healthBarList[i].name)); } }
private void EntityStats_OnDamage(object sender, System.EventArgs e) { for (int i = 0; i < healthBarList.Count; i++) { // If the health bar's current value is not equal to the new value, then the bar should update. if (healthBarList[i].foregroundBarImage.fillAmount != EntityStats.Instance.GetNormalisedHealthOfEntity(healthBarList[i].name)) { holdingData = healthBarList[i]; holdingData.sliderTimer = holdingData.sliderBarDeplenishTimer; healthBarList[i] = holdingData; SetBarPercentage(healthBarList[i], EntityStats.Instance.GetNormalisedHealthOfEntity(healthBarList[i].name)); } } }
private void Update() { for (int i = 0; i < healthBarList.Count; i++) { holdingData = healthBarList[i]; holdingData.sliderTimer -= Time.deltaTime; healthBarList[i] = holdingData; if (healthBarList[i].sliderTimer < 0f) { if (healthBarList[i].foregroundBarImage.fillAmount < healthBarList[i].backgroundBarImage.fillAmount) { healthBarList[i].backgroundBarImage.fillAmount -= healthBarList[i].sliderBarDeplenishSpeed * Time.deltaTime; } } else if (healthBarList[i].foregroundBarImage.fillAmount > healthBarList[i].backgroundBarImage.fillAmount) { healthBarList[i].backgroundBarImage.fillAmount = healthBarList[i].foregroundBarImage.fillAmount; } ; } }
private void SetBarPercentage(healthBarData _healthBar, float _healthNormalized) { _healthBar.foregroundBarImage.fillAmount = _healthNormalized; }