How to delay animation after OnTriggerEnter??

I did a lot of research before posting this ? and I can’t find the right answer. Here is my script.

`var doorClip : AnimationClip;

function OnTriggerEnter (player : Collider){
if(player.tag == "Player")
GameObject.Find("wall1").animation.Play("wall moving in");
}`

And now I want to add a 4 second delay before the animation plays. This must be an easy fix. Please tell me what to add and where! Thanks!!!

You need a Coroutine. In C# it would be:

public IEnumerator DelaySomething()
{
yield return new WaitForSeconds(4f);
DoSomething();
}

There’s a ton of examples on Coroutines on the internets.

You can just add:

  yield WaitForSeconds(4f);

…to your OnTriggerEnter() before you call your animation.Play(). Note you may want to handle the situation where another OnTriggerenter() comes in before the 4.0 seconds are complete.