- Home /
Question by
Nicholander · Mar 24, 2015 at 06:19 AM ·
scripting problemsceneleveldelay
How Do You Make A Script Start Another Scene/Level? (And Add A Delay For Something In A Script?)
I'm a newb here pretty much, so the answer probably pretty obvious, but I'm trying to add another level/scene in this game of mine, but I just can't seem to figure it out. What am I supposed to add as code?
Also, it'd be really helpful too if someone could tell me how to add a 5 second delay before the game went to the next level.
Thanks in advance for helping!
Comment
Answer by K_Tec · Feb 23, 2017 at 07:52 PM
Hello,
First you have to add your current level and the level to load the the Build settings. !!!Important: Add using UnityEngine.SceneManagement;
to the top of the code were the namespaces are. Than try this (Unity 5.5, C#)
public string leveltoload;
public int loaddelay;
void Start(){
Timer();
}
IEnumerator Timer(){
yield return new WaitForSeconds(loaddelay);
SceneManager.LoadScene(leveltoload);
yield break;
}
Have a nice Day,
Kerbo :)