Invoke not working,invoke not working

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);
}

}

you accidentally duplicated your message

Hi,
I have not used invoking methods by it’s name before. According to Unity documentation, it’s better to use coroutines for something like this. (The documentation might be confusing so you might wanna look up a video on this)

With coroutines you can stop the execution and resume it later.

Your code with a coroutine would look like this:

public IEnumerator Restart(float f)
    {
        yield return new WaitForSeconds(f);
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

and then the call:

StartCoroutine(Restart(restartDelay));

You should use StartCoroutine(IEnumerator stuff).