When the player gets destroyed I want to show a Game Over OnGUI and wait for 5 seconds to load the next scene (restart/quit/addscore scene).
void OnDestroy()
{
Application.LoadLevel(Application.loadedLevel + 1);
}
When the player gets destroyed I want to show a Game Over OnGUI and wait for 5 seconds to load the next scene (restart/quit/addscore scene).
void OnDestroy()
{
Application.LoadLevel(Application.loadedLevel + 1);
}
All you need is a coroutine.
bool showGUI = false;
void OnDestroy()
{
StartCoroutine("LoadNextLevel");
}
void OnGUI() {
if(showGUI) {
// Show the content of Game Over GUI
} else {
// Hide the Game Over GUI
}
}
IEnumerator LoadNextLevel() {
showGUI = true;
yield return new WaitForSeconds(5);
showGUI = false;
Application.LoadLevel(Application.loadedLevel + 1);
}