Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Delay before loading a new scene

Discussion in 'Scripting' started by Neon_Apollo, Jan 11, 2018.

  1. Neon_Apollo

    Neon_Apollo

    Joined:
    Dec 8, 2017
    Posts:
    13
    Hey, so I have this simple script for loading a new scene, but I would like to add a short timer between when the new scene button is pressed and when the new scene is loaded.
    Here is my script:
    Code (CSharp):
    1. public class LoadNew : MonoBehaviour {
    2.  
    3.     public void NewSceneLoader(int SceneIndex)
    4.     {
    5.         SceneManager.LoadScene(SceneIndex);
    6.     }
    7. }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,488
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Try a coroutine :)

    Start the coroutine instead of loading the scene , as you are now. Add a yield for seconds (time to wait) in it, and then afterthat add the code you to change scenes.

    Or Invoke, as @mgear suggested lol. I keep forgetting that.
     
    Deleted User likes this.