Hi guys, I’ve been working on a C# script to load a new scene after 7 seconds. I’ve got no errors or warnings and my scene IS called ‘MainMenu’ so any ideas as to why this isn’t actually loading the scene?
I’ve tried building the project and made sure all the scenes were added - any ideas?
using UnityEngine.SceneManagement;
using UnityEngine;
using System.Collections;
public class Load_MainMenu : MonoBehaviour {
public void ModeSelect()
{
StartCoroutine("Wait");
}
IEnumerator Wait()
{
yield return new WaitForSeconds(7);
SceneManager.LoadScene("MainMenu");
}
}
using UnityEngine.SceneManagement;
using UnityEngine;
using System.Collections;
public class Load_MainMenu : MonoBehaviour
{
public void ModeSelect()
{
StartCoroutine("Wait");
}
IEnumerator Wait()
{
yield return new WaitForSeconds(7f);
Application.LoadLevel("MainMenu");
}
}
Make Sure the timescale hasn’t been 0. The WaitForSeconds is influence by the timescale. You can test it on the editor, And Check from the project setting → Time to see if the timescale has been set to 0. And are you sure that you had call the ModeSelect function? Maybe you can log a message to make sure the function had been called correct.
EDIT: Final code to include Inspector fields to clarify what scene to load as well as delay time:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class LoadSceneWithDelay : MonoBehaviour
{
public string SceneToLoad = "";
public float DelayTime = 3.0f;
public void Start()
{
StartCoroutine("Wait");
}
private IEnumerator Wait()
{
yield return new WaitForSeconds(DelayTime);
SceneManager.LoadScene(SceneToLoad, LoadSceneMode.Single);
}
}
I know this Is not actually an answer but I’m getting the same problem!