Trying to Lerp a fill amount according to a countdown coroutine

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?

It’s skipping because it’s instructed to wait for a whole second.

yield return new WaitForSeconds(1);
countDown -= 1f;

Try this instead:

IEnumerator Flash()
{
    countDown = 5f;
    invincible = true;
    shieldRotator.shieldAppear = true;
    
    while (countDown > 0f)
    {
        Debug.Log(" count: " + countDown);
        yield return new WaitForEndOfFrame();
        countDown -= Time.deltaTime;;
    }
    
    countDown = 0f;
    invincible = false;
    shieldRotator.shieldAppear = false;
    yield return null;
}