how to write script to restart game after game over

hi, i am using this code to restart game but i dont know how do i add? i just want if i push space button then the game is restart to from beginning of mainScene.

void Update()
{
	if (GameStateManager.GameState == GameState.Dead)
	{
		if (WasTouchedOrClicked())
		{
			restart game
		}
	}
}

bool WasTouchedOrClicked()
{
	if (Input.GetKey(KeyCode.Space))
		return true;
	else
		return false;
}

Add to the top of your class:

using UnityEngine.SceneManagement;

Update your update method to reload the current scene either by name or index.

void Update()
 {
     if (GameStateManager.GameState == GameState.Dead)
     {
         if (WasTouchedOrClicked())
         {
             // Get active scene name and reload that scene based off name, could also buildIndex instead of name.
             SceneManager.LoadScene(SceneManager.GetActiveScene().name);
         }
     }
 }

If you’re not looking to reload but want it in a “new game” state, you will need to code out all the reset methods for your game and gameobject locations.