Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Load Scene with Coroutine

Discussion in 'Scripting' started by Tpleme, Jun 29, 2019.

  1. Tpleme

    Tpleme

    Joined:
    May 10, 2019
    Posts:
    7
    Hello,

    I have a piece of code that loads a scene and then after 4 seconds loads another. But somehow it doesn't load the second scene.

    I am kinda learning unity so it may be a little mistake but i cant figure it out.

    Any help is appreciated

    Code (CSharp):
    1. public void StartGame()
    2.     {
    3.         SceneManager.LoadScene("LoadingScreen");
    4.  
    5.         Debug.Log("Loading in 4 seconds");
    6.  
    7.         StartCoroutine(StartDelay());
    8.     }
    9.  
    10.     IEnumerator StartDelay ()
    11.     {
    12.         Debug.Log("Coroutine Loaded");
    13.  
    14.         yield return new WaitForSeconds(4f);
    15.  
    16.         Debug.Log("Loaded");
    17.  
    18.         SceneManager.LoadScene("Level01");
    19.         FindObjectOfType<AudioManager>().Play("Ambiente");
    20.         Health.ResetLife();
    21.        
    22.     }
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
  3. Tpleme

    Tpleme

    Joined:
    May 10, 2019
    Posts:
    7
    oh i see,

    thank you