- Home /
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!!!!
Answer by robertbu · Nov 09, 2014 at 07:03 PM
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.
Answer by barjed · Nov 09, 2014 at 06:53 PM
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.
I'm not familiar with any scripting, I just dove right into unity. watching tutorials and finding stuff online. I'm using javascript. Anyone know what it would be for javascript?? edit** I'm just going to add a big delay in the animation while I'm making the animation with unity. That seemed to work out good. just a hassle.