I already have this code:
public void ChangeToScene(string sceneToChangeTo)
{
Application.LoadLevel(sceneToChangeTo);
}
And I want to have 1 second wait time before I change scene. But i do not know how and I have not been able to find something to help me yet.
Use a coroutine.
So instead of using
ChangeToScene(sceneName);
you use
StartCoroutine(ChangeToScene(sceneName));
and for your function, change it to
public IEnumerator ChangeToScene(string sceneToChangeTo)
{
yield return new WaitForSeconds(1);
Application.LoadLevel(sceneToChangeTo);
}
so that it’s a coroutine instead of a normal method.
using Coroutine
public void ChangeToScene(string sceneToChangeTo)
{
StartCoroutine(DoChangeScene(sceneToChangeTo,1f);
}
IEnumerator DoChangeScene(string sceneToChangeTo,float delay)
{
yield return new WaitForSeconds(delay);
Application.LoadLevel(sceneToChangeTo);
}
Thank you @Juneyee
The function seems to work but this line:
StartCoroutine(ChangeToScene(sceneName));
Is all underlined in red and i dont know why.