I have created a progress bar system that lerps the value over a duration to provide some life to the progress bars.
I've done this using a coroutine that gets called each time a value (such as life or exp) gets modified.
The problem with this is, if the coroutine gets called in rapid succession, i.e. before the previous instance of the coroutine is finished, the lerped values inside the progress bar get messed up. They get fixed at the next coroutine call, but it kind of bothers me, so if someone can provide some insight into this, or maybe a workaround or an alternative way of accomplishing this, I would very much appreciate it.
The code for the coroutine I'm using is this:
private IEnumerator FillLerp(int currExp, int expNeed)
{
float lerpDuration = 2f;
float lerpSpeed = 3f;
float i = 0f;
float amountToFill = (float)currExp / expNeed;
while (i < lerpDuration)
{
yield return null;
_experienceBarFill.fillAmount = Mathf.Lerp(_experienceBarFill.fillAmount, amountToFill, Time.deltaTime * lerpSpeed);
i += Time.deltaTime;
}
}