How to automatically stop car when fuel ends up ?

So, I want to achieve a simple functionality here. On KeyCode.F pressed, the booster/fuel fills up and On KeyCode.W pressed (only once no need to hold) the car starts consuming booster/fuel. So far it’s working good.

The Real problem I am facing is, to stop the car without pressing any key. I tried to add brakeTorque but i think that can’t do this job. Any help will be appreciated… (Sorry for bad english)

    void Update()
    {

        if (Input.GetKey(KeyCode.F))
        {
            StartCoroutine(FillBooster());
        }
        
        if (Input.GetKeyDown(KeyCode.W))
        {
            isMoving = true;
            StartCoroutine(ConsumeBooster());

        }
     }

IEnumerator ConsumeBooster()
    {
        while (!isBoosterEmpty())
        {
            boostBar.fillAmount -= Time.deltaTime/2;
            SetMotorTorque(motorForce);

            print("boost left : " + boostBar.fillAmount)
            yield return null;
        }
        if (isBoosterEmpty())
        {
            ApplyBrake();

            yield return null;
        }
    }

 private void ApplyBrake()
    {
        print("is booster empty : " + isBoosterEmpty());

        // here I tried to use brakeTorque but I think it doesn't work that way. 
    }

Get rid of the while loop and just have

IEnumerator ConsumeBooster()
{
boostBar.fillAmount -= 0.1f;
SetMotorTorque(motorForce);
yield return new waitforseconds(2);
print("boost left : " + boostBar.fillAmount)
if(boostBar.fillAmount <= 0)
{ApplyBrake();}

}

Keep in mind you will need to start the CoRoutine again after 2 seconds, so I’d suggest just using a normal void and -= using delta time, as you already have done.


edit: Try this instead.

void Update()
{
         
         
  if (Input.GetKeyDown(KeyCode.W))
  {
   isMoving = true;
   ConsumeBooster();
  }
}

void ConsumeBooster() 
{ 
  if(boostBar.fillAmount > 0) 
  {
    boostBar.fillAmount -= 2 * Time.deltaTime;
    SetMotorTorque(motorForce); 
    print("boost left : " + boostBar.fillAmount) 
  }
  else
  {
    ApplyBrake();
  }

}

Please help me with this