Idle counter

Hello, I’m trying to implement a counter that counts down whenever the player input stops. If it reaches 0, an idle animation begins, and whenever input begins again the counter is reset. I’m getting close to having it work, however I’m not sure what to use to get it to subtract properly. This might not be the best way to do it, but with some modifications to an example I found online I’ve come up with this:

//no input, begin countdown
	if(targetDirection == Vector3.zero) 
	{
		//The time left before idle_sleep kicks in
		timeLeft = startTime - Time.time;
		//Don't let the time left go below zero
		timeLeft = Mathf.Max (0, timeLeft); 
		if(timeLeft == 0)
		{
			sleeping = true;
		}
	}
	
	//input recieved, reset timer
	if(targetDirection != Vector3.zero) 
	{
		timeLeft = startTime;
	}
	
	//input beginning again, end idle animation and reset timer
	if(sleeping  targetDirection != Vector3.zero)
	{
		//new input, reset timer
		timeLeft = startTime;
		sleeping = false;
	}

Any tips would be much appreciated. Thanks!

something like this?

const float timeout = 10.0f;
float countdown = timeout;
bool idle = false;
...

if(!idle)
{
    if(moveDir != Vector3.zero)
        countdown = timeout;

    if(countdown <= 0.0f)
    {
        idle = true;
        // Started-being-idle code here.
    }
    countdown -= Time.deltaTime;
}
else
{
    if(moveDir != Vector3.zero)
    {
        idle = false;
        countdown = timeout;
        // Stopped-being-idle code here.
    }

    // Still-being-idle code here.
}

Yes, that works great! Thanks!