The body of '' cannot be an iterator block because 'void' is not an iterator interface type???

Just now got this problem not knowing what to do. Trying to get a splash screen going by making the script wait for 5 seconds then switch scenes. Help?

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class splashScreen : MonoBehaviour {

	// Update is called once per frame
	void Update () {
		yield return new WaitForSeconds (5.0f);
		SceneManager.LoadScene("MainMenu1");
	}
}

Yield can only be used inside a Coroutine.

void Update ()
{
  StartCoroutine( NextScene() );
}

IEnumerator NextScene()
{
  yield return new WaitForSeconds (5.0f);
  SceneManager.LoadScene("MainMenu1");
}

I am using here a Singleton pattern to create a GameManager and my solution is:

  • make sure you have this on top:

    //010 fix the SceneManagement warning !
    using UnityEngine.SceneManagement;

  • //01 replace T with this class (GameManager) public class GameManager : Singleton { //02 property that keeps track of the time remaining

  • and finally I use asyncload :

    // Update is called once per frame
      void Update()
      {
          //05 subtracts the time since last frame from time remaining
      	TimeRemaining -= Time.deltaTime;
    
      	//06 checks if time remaining is 0 or negative
      	if(TimeRemaining <= 0)
      	{
      		//07OLD reloads the current Level
      		//Application.LoadLevel(Application.loadedLevel); OBSOLETE
    
      		//011 calls the Coroutine for AsyncLoad
      		StartCoroutine(LoadNextAsyncScene());
      	}
      }
    

    // fix the warning
    IEnumerator LoadNextAsyncScene()
    {
    //07 load the next scene async
    AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(“02TriggerEventHealth”);
    //08 reset the timer for the next game back to maximum time
    TimeRemaining = maxTime;
    //09 wait for the async scene to full load
    while (!asyncLoad.isDone)
    {
    yield return null;
    }
    }