1
votes

I have a problem. Now I'm developing game in Unity when the condition is score 2. I want to wait for ten seconds before do the code change scene (Application.LoadLevel) (I'm using C# for develop)

But this code when score = 2 It will change to "scenea_5" It can't wait for ten seconds

void OnTriggerEnter( Collider collider ){

    if (collider.name == front_hztleft) {
        audio.Play ();
    }

    if (collider.name == left_hztleft) {
        audio.Play ();
        score ++;
        Debug.Log (string.Format (scoreSyntax, score));
        endtime = DateTime.Now.ToString("HH:mm:ss");
        InsertResult(); 
    }


    if (score == 2) { 
        StartCoroutine(Waiting());
        Application.LoadLevel("scene_a5");

    }
}
IEnumerator Waiting()
{
    yield return new WaitForSeconds (10);
}

It can run and compile not without error.

1

1 Answers

1
votes

Put the scene loading inside the Coroutine.

 yield return new WaitForSeconds(10);
 Application.LoadLevel("scene_a5");