Hello guys,
I’m stuck since a too long time on the polishing of my gauge management.
I’ve a scrollbar which I use to represent the life of my Hero : when he becomes hurted, I I called a fonction which calls an IEnumerator which progressively decrease the life amaount and the gauge. But the fact is that when monsters trigger the event before the end of another instance of the enumerator, results become weird.
I’ve wanted to try with a lerp but I’m not convinced by the result, do you have any ideas to improve my code ?
public void SetDamage(float damage)
{
StopCoroutine("ChangeLifeBar");
if (lifeBar_is_ok)
{
StartCoroutine(ChangeLifeBar(damage));
}
}
IEnumerator ChangeLifeBar(float damage)
{
float futureLife = life - damage;
lifeBar_is_ok = false;
while (!lifeBar_is_ok)
{
life--;
hero_life_bar.size = life / 100f;
lifeBar_is_ok = futureLife == life;
yield return null;
}
}
Thanks !