I am using an Invoke command to end my game after displaying an exit scene for a few seconds. When I open this scene I want it to display for a few seconds and then I want the game to stop. In the inspector I have “quitTime = 2”
using UnityEngine;
using System.Collections;
public class QuitGameAfterTime : MonoBehaviour {
public float quitTime;
void Awake ()
{
print ("QuitGameAfterTime: Awake, quitTime=" + quitTime);
Invoke("QuitGame", quitTime);
}
void QuitGame()
{
print ("QuitGameAfterTime: QuitGame");
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#elif (UNITY_IPHONE)
Application.Quit();
#elif (UNITY_ANDROID)
Application.Quit();
#else
Application.Quit();
#endif
}
}
When I run my game and go directly to the exit scene everything works fine and the game ends after 2 seconds. Even if I go to a credits scene or goto a settings scene and then go to the exit scene everything works fine (game ends after 2 seconds). However if I play my game, leave the game scene and then go to the exit scene it does not work. The Awake function runs but the Invoke never does. This is a very consistent problem. I have no idea what could be part of my game to cause this?!?!
Does anyone have any ideas?