Hello, im trying to learn coding using this guide: GAME OVER - How to make a Video Game in Unity (E08) - YouTube
he uses invoke to have a delay between losing and restarting the game, but for some reason my code doesnt work. I cant seem to find the error and i dont get an error in the unity console.
This is my code:
using UnityEngine;
using UnityEngine.SceneManagement;
public class Gamemanager : MonoBehaviour
{
bool gameHasEnded = false;
public float restartDelay = 1f;
public GameObject completeLevelUI;
public void CompleteLevel()
{
completeLevelUI.SetActive(true);
}
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Invoke("Restart", restartDelay);
}
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
,Hello, im currently trying to learn to code in unity. I am using this guide:GAME OVER - How to make a Video Game in Unity (E08) - YouTube
and he uses invoke as a method to have a delay between losing the game, and the game restarting. But the invoke doesnt work for me. I am sure that i have written it right, but you never know.
This is my code:
using UnityEngine;
using UnityEngine.SceneManagement;
public class Gamemanager : MonoBehaviour
{
bool gameHasEnded = false;
public float restartDelay = 1f;
public GameObject completeLevelUI;
public void CompleteLevel()
{
completeLevelUI.SetActive(true);
}
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Invoke("Restart", restartDelay);
}
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}