- Home /
WaitForSeconds not working in OnTriggerEnter event
I have a ball object, when it hits the net, I want there to be a delay of 2 seconds, and then only should it continue. Calling WaitForSeconds doesn't make a difference, there is no delay whatsoever. Any idea what I'm doing wrong?
void OnTriggerEnter(Collider theCollider) { if(theCollider.gameObject.name == "Netting") { Debug.Log("The ball hit the netting"); DoDelay(); }
gameManagerScript = gameManagerScript.GetComponent<GameManagerScript>();
gameManagerScript.GrantPoint();
}
IEnumerator DoDelay() { yield return new WaitForSeconds(2); }
Answer by Thom Denick · Feb 12, 2011 at 08:32 PM
Here's the correct formatting in C#:
public void StartIntroAnimation() { StartCoroutine(dummyPigDelay()); }
private IEnumerator dummyPigDelay() { yield return new WaitForSeconds (8.0f); PlayPigDanceNow(); }
Answer by Eric5h5 · Feb 12, 2011 at 08:19 PM
You're not yielding when you call DoDelay, and in C# you also have to use StartCoroutine.