[Edit: Scroll down for the solution]
Hi there.
I’m experiencing the same issue.
Further more, if I call Invoke (method, 0) it will work. If I replace the “0” with any other number, then the Invoke only works as described by the OP (only if the level is loaded first, and not when the level is loaded using Application.LoadLevel.
I have also tried to put the level inside void OnLevelWasLoaded, and then I’ve used Application.SendMessage(“OnLevelWasLoaded”, Application.loadedLevel) in Start. Still doesn’t work as expected.
Code:
void Start()
{
gameObject.SendMessage (“OnLevelWasLoaded”, Application.loadedLevel); // This
}
void onLevelWasLoaded( int level )
{
splashPanel.SetActive (true);
Invoke ("WaitCloseSplash", 0.5F);
}
void WaitCloseSplash ()
{
splashPanel.SetActive (false);
}
OP, can you confirm that if you call Invoke with 0 it works?
Question: Did you find any workarounds? I’ve been fiddling with this for a couple of days now.
Code that did not work:
void Start()
{
Invoke("WaitCloseSplash", 1); // works if 1 is replaced with 0
}
void WaitCloseSplash()
{
splashPanel.SetActive (false);
}
void Start()
{
StartCoroutine("WaitCloseSplash");
}
IEnumerator WaitCloseSplash()
{
yield return new WaitForSeconds(2); // works if 1 is replaced with 0
splashPanel.SetActive (false);
}
The Real Culprit:
Time.timeScale = 0;
Somewhere in another file the game was paused before returning to the scene that was running Invoke or StartCoroutine + yield return new waitforseconds
The Solution:
time.timeScale = 1; // un-pause the game before switching levels
Application.LoadLevel(0); // or any other level
Or:
Time.timeScale = 1; // Make sure that the game is not paused before calling StartCoroutine and using yield return new WaitForSeconds
StartCoroutine( "WaitCloseSplash" );
OR:
Time.timeScale = 1; // Make sure that the game is un-paused before waiting.
yield return new WaitForSeconds(1);
Or:
time.timeScale = 1; // Make sure that the game is not paused before using Invoke
Invoke("WaitCloseSplash", 2); // My preferred way of delaying execution.
The Short Answer: Make sure that the game is not paused before using any execution delay techniques!
P.S. I know that this thread is somewhat old, but I’m posting here because there is no answer provided yet and maybe someone will stumble across this when searching for a solution, just like I did.