I'm trying to fix a health bar and I forgot where it came from. The bar is not sliding in the unity editor. When damage is taken a red background bar should follow the front bar with some delay to cause a shrink effect, and when healed the back bar should set to what the new health is going to be and then the front bar slide up to the backbar (also, should be green when adding health)
{
float fillF = frontHungerBar.fillAmount;
float fillB = backHungerBar.fillAmount;
float hFraction = Hunger / 100;
if (fillB > hFraction)
{
frontHungerBar.fillAmount = hFraction;
backHungerBar.color = Color.red;
HunlerpTimer += Time.deltaTime;
float percentComplete = HunlerpTimer / chipSpeed;
percentComplete = percentComplete * percentComplete;
backHungerBar.fillAmount = Mathf.Lerp(fillB, hFraction, percentComplete);
}
if (fillF < hFraction)
{
backHungerBar.color = Color.green;
backHungerBar.fillAmount = hFraction;
HunlerpTimer += Time.deltaTime;
float percentComplete = HunlerpTimer / chipSpeed;
percentComplete = percentComplete * percentComplete;
frontHungerBar.fillAmount = Mathf.Lerp(fillF, backHungerBar.fillAmount, percentComplete);
}
}```