How to make a variable true for a certain amount of time?

So I want to be able to make my variable true for a certain amount of time even when the parameters are not filled in so like if my code were like this

if (!myCapsuleCollider2D.IsTouchingLayers(LayerMask.GetMask(“Ground”)))

then when the capsule collider is no longer touching the ground the variable is still true for a second or so.

You can use a Coroutine, which allows you to wait a certain amount of time. Like this:

void Update()
{    
if(!myCapsuleCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground"))){
StartCoroutine(wait());
}
}

IEnumerator wait()
{
yield return new WaitForSeconds(1);
variable = false;
}

EDIT: it seems that unity forums has ate my tabs