How to add return functionality to the script if input is not detected

Can someone help me out here, please;

Here below, is my code. So far, its working though I’m trying to add another functionality to it.

The script allows my character to attack when isAttacking is true and wait until cooldownDuration is complete but I also would like it to return if the Attack wasn’t done (even when canAttack is true) : that’s why I have the returnTime variable
{

public bool canAttack;
public bool isAttacking;

public float maxTime;
public float trueTime;

public float returnTime;
public float cooldownDuration;

PlayerInput input;
PlayerCharacter character;

private void Awake()
{
    input = GetComponent<PlayerInput>();
    character = GetComponent<PlayerInput>();
    trueTime = 0;
}

private void FixedUpdate()
{
    StartCoroutine(GroundAttackCheck());
}

IEnumerator GroundAttackCheck()
{
    canAttack = false;
    isAttacking = false;

    if (!(character.isGrounded && input.interactHeld))
    {
        canAttack = false;
    }

    if (character.isGrounded && input.interactHeld)
    {
        trueTime += Time.deltaTime;

        if (trueTime < maxTime)
        {
            canAttack = true;
        }

        if (canAttack && input.slicingHeld)
        {
            isAttacking = true;
            trueTime = maxTime;

            yield return new WaitForSeconds(cooldownDuration);
            trueTime = 0;
        }

        if (trueTime >= maxTime)
        {
            trueTime = maxTime;
        }
    }
}

}

Then you can use a Invoke with 2 seconds.

IF detect de atack, execute CAncelInvoike.

In no detection, the invoke will be executed after that 2 seconds.

Bye!