Trigger Animation After Idle for 5 Seconds

I keep trying not to ask a question until I have exhausted my other options. I just started trying to read, write and comprehend script a few days ago. If I ask a stupid question or make hilarious syntax mistakes, forgive my ignorance.

I want to trigger an animation after my character has been motionless for 5 seconds. I think I’m on the right track but I can’t quite get there.

I want the animation to trigger after the wait, be interrupted by any movement and be able to trigger again if the wait condition is met. Also, how would I set up the transitions efficiently in the Animator?

Any help would be greatly appreciated.

void Start()
{
    anim = GetComponent<Animator>();
    StartCoroutine("waitFiveSeconds");
}      

    IEnumerator waitFiveSeconds()
    {
        yield return new WaitForSeconds(5);
        anim.Play("Wiggle");
    }
}

}

You have mostly correct syntax and code displayed. However, depending on if your animation has a parameter of a bool or trigger may cause it to not play. If it’s a trigger, then you would need, anim.SetTrigger(“Wiggle”) (make sure to unset or reset if you call another animation). If the parameter is a bool, then you should use anim.SetBool(“Wiggle”, true); I have attached a screen shot of how to setup parameters. In the image, you’d right click on an animation, then select “Make Transition”. After that, you’ll drag the arrow to the animation state you want to call (make sure it has a way to get back to the starting animation state). After that, you’d click on the white arrow and add in the condition you need by clicking on the “+” icon.