I'm using a coroutine and the code is stopping at yield return without resuming after the given time
Solution 1:
When you do
SceneManager.LoadScene("Loading");
the current scene is unloaded and this component most probably along with it so your Coroutine is only executed to the first yield
and then never continues.
Also you really don't need that delegate. Why not simply call your method directly like this:
public class LoadNextLevel : MonoBehaviour
{
private IEnumerator LoadFunc()
{
var levelnum = int.Parse(gameObject.scene.name[5].ToString());
levelnum++;
// Make sure this is not destroyed when the scene is unloaded
DontDestroyOnLoad (gameObject);
SceneManager.LoadScene("Loading");
yield return new WaitForSeconds(2f);
SceneManager.LoadScene("Level" + levelnum);
// Then once you don't need this anymore now destroy it
Destroy (gameObject);
}
public void Load()
{
StartCoroutine(LoadFunc());
}
}
Instead of going by strings you could also use
var nextIndex = SceneManager.GetActiveScene().buildIndex + 1;
and then later
SceneManager.LoadScene(nextIndex);