Load Scene, wait some seconds and load another scene

Good morning :slight_smile:

I have a problem. I’m going to load a Scene, wait some seconds and want load another scene.
Here’s my Code:

public class mouseThrow_Trigger : MonoBehaviour
{

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Maus_Test"))
        {
            print("Mouse_Trigger works");
            StartCoroutine(loadScene());
        }
    }

    IEnumerator loadScene ()
    {
        SceneManager.LoadScene("Maus");
        yield return new WaitForSeconds(3);
        SceneManager.LoadScene("Raum");
    }
}

Can you tell me where my mistake is? (using UnityEngine.SceneManagement is already imported)

1 Like

Create a script in the “Maus” scene that waits for 3 seconds and then loads the “Raum” scene.
Once you execute LoadScene, the code that follows won’t execute afaik. :slight_smile:

Your mistake is that you assume this script is still running after the scene has been changed.

Thanks for your help, it works :slight_smile: