Enable collider then disable it after a certain amount of time

Hi All,
I am making an attack animation for my game and when you attack, I want it to enable a collider for 0.5f seconds. I have a script that enables it but I am not sure how to disable it after 0.5 seconds…
Heres what I have so far

void Update () {
    if (Input.GetKeyDown(KeyCode.J))
    {
        GameObject.Find("player").GetComponent<Animator>().Play("Attack");
        m_Collider.enabled = true;
        animator.SetTrigger("attacked");

       //Wait for 0.5f seconds

        m_Collider.enabled = false;
    }
}

thanks, Larry

To wait for half a second, you can do it in an IEnumerator, here’s what I would put instead of your comment

StartCoroutine(waitForSec(.5f));

And down below have a coroutine that looks something like

private IENumerator waitForSec(float sec){
     yield return new WaitForSeconds(sec);
     m_Collider.enabled = false;

}

Cheers! (you can also hard code the time into the method, it’s just good practice to keep it like that :wink: