Hello,
I’m trying to display the gameOver scene I made and after some time, like 5s, restart the game by loading the game scene.
I made this, but it doesn’t restart the game and stays on the gameOver scene.
using UnityEngine;
using UnityEngine.SceneManagement; // Quand on à besoin de faire appel à une autre scene
public class GameManager : MonoBehaviour {
bool gameEnd = false;
public float restartDelay = 3f;
public void EndGame()
{
if (gameEnd == false)
{
gameEnd = true;
Debug.Log("Game OVER");
Invoke("Restart", restartDelay); // Invoke sert à appeller la fonction à partir d'un certain temps
SceneManager.LoadScene("Terrain", LoadSceneMode.Additive);
SceneManager.LoadScene("FinLoose");
}
}
void Restart ()
{
SceneManager.SetActiveScene (SceneManager.GetSceneByName("Terrain"));
}
}