Check if something just pass through an object or stay some fixed time on it

Hello guys, i’m new on it and my English is not so good, so be nice! Please :slight_smile:

what i want to do is:

if the player pass trough an object, nothing happens!
but if it stays on it for example 2 seconds, something happens.

i’m using onTriggerEnter2D(), onTriggerExit2D and coroutine.
but still not working, i pass trough the object and 2 seconds later it does the hellthing.

Thank you so much!!

[RESOLVED]

Coroutine lastRoutine = null;

private void OnTriggerEnter2D(Collider2D trigger2D)
{
    if (trigger2D.gameObject.CompareTag("Something"))
    {
        print("On it!!!");
        lastRoutine = StartCoroutine(WaitToDo());
    }
}

IEnumerator WaitToDo()
{
    yield return new WaitForSeconds(5.0f); // wait 5 seconds to "Do Something"
    print("Do Something");
}

private void OnTriggerExit2D(Collider2D trigger2D)
{
    if (trigger2D.gameObject.CompareTag("Somethign"))
    {
        StopCoroutine(lastRoutine);
    }
}