Hi there.
I have a countdown coroutine for a 5-second shield element in my game:
IEnumerator Flash()
{
countDown = 5f;
invincible = true;
shieldRotator.shieldAppear = true;
while (true)
{
Debug.Log(" count: " + countDown);
yield return new WaitForSeconds(1);
countDown -= 1f;
if (countDown == 0)
{
shieldRotator.shieldAppear = false;
invincible = false;
yield break;
}
}
}
I then have a script on a UI image which reduces the fill of a bar from 1 to 0 depending on this count:
void FixedUpdate()
{
HandleBar();
}
void HandleBar()
{
content.fillAmount = PlayerController.countDown / 5f;
}
How can I Lerp the fill amount so it doesn’t jump from 1 to 0.8 to 0.6 to 0.4 to 0.2 to 0?