Adding a Restart Feature

I am looking to simply adding a “Press ‘R’ to Restart” to the Survival Shooter Tutorial aka “The Nightmare”. The issue I am having is that the tutorial sets you up with a restart timer (although I believe I have removed this). I added the code that I know to do this (learned from the Space Shooter tutorial) and although it all seems to work the game still automatically restarts itself. I do not know what I am doing wrong. Here is the code I have so far:

using UnityEngine;
using UnityEngine.SceneManagement;


public class GameOverManager : MonoBehaviour

{
    public PlayerHealth playerHealth;

    Animator anim;
    private bool gameOver;
    private bool restart;


    private void Start()
    {
        gameOver = false;
        restart = false;
    }


    void Awake()
    {
        anim = GetComponent<Animator>();
    }


    void Update()
    {
        if (playerHealth.currentHealth <= 0)
        {
            anim.SetTrigger("GameOver");
            gameOver = true;

            if (gameOver)
            {
                if (Input.GetKeyDown(KeyCode.R))
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
                    restart = true;
                }

            }

        }
    }
}

The timer must still be setup somewhere because your code is fine, there must be another script telling this script for ‘gameOver’ to be true.

if you die, just load the scene again.

using UnityEngine.SceneManagement;
 
public void loadlevel(string level)
{
SceneManager.LoadScene(level);
 
}