Can't get WaitForSeconds() to work

Hello, guys,

Here’s my code. I basically wanted to wait a few seconds before loading the level so that the game could show the animation for the explosion. However, it doesn’t wait. And “After Wait” doesn’t show in the log. I hope you can help me. I’ve tried a bunch of things but nothing has worked so far.

void OnTriggerEnter (Collider otherObject){

  PlayerScript playerScript = (PlayerScript) otherObject.gameObject.GetComponent("PlayerScript");

  Instantiate (ExplosionPrefab, playerScript.transform.position, playerScript.transform.rotation);

  Destroy (otherObject.gameObject);

  Destroy(this.gameObject);

  StartCoroutine (wait());

  Application.LoadLevel(1);

}

IEnumerator wait(){

  Debug.Log ("before wait");

  yield return new WaitForSeconds (5.0f);

  Debug.Log ("After Wait");

}

The load level needs to be inside the co-routine because StartCoroutine will just return immediately it hits the wait and will continue after 5 seconds (printing your debug - but the new level has already loaded!!).

Also object that are running should not be destroyed or disabled as this stops the coroutines execution.