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