Can't get my Player to respawn

Hey guys.

I’ve tried following the Space Shooter tutorial here

It’s worked out wonderfully, up until chapter 15: Ending the game - Where I can’t get the respawn script to work.

I tried putting in a debug.Log to see if it even responded when I press R (to respawn), but my debug Log never appeared, so I guess it doesn’t respond.

My best guess is, restart isn’t true, and I don’t know why. It SHOULD become true, after I die. Any help would be MUCH appreciated as I would like to finish this project. The code for my gamecontroller:

using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour {
	 
	public GameObject hazard;
	public Vector3 spawnValues;
	public int hazardCount;
	public float spawnWait;
	public float startWait;
	public float waveWait;
	public GUIText scoreText;
	public GUIText restartText;
	public GUIText gameOverText;
	private int score;
	private bool gameOver;
	private bool restart;
	void Start ()
	{
		gameOver = false;
		restart = false;
		restartText.text = "";
		gameOverText.text = "";
		score = 0;
		UpdateScore ();
		StartCoroutine (SpawnWaves ());
	}
		void update ()
	{ 	
		if (restart)
		{
			if(Input.GetKeyDown (KeyCode.R))
			{
				Debug.Log ("If you can see this, this part of the code should work fine");
				Application.LoadLevel (Application.loadedLevel);

			}
		}
	}
	IEnumerator SpawnWaves ()
	{
		yield return new WaitForSeconds (startWait);
		while (true)
		{

		for (int i = 0; i < hazardCount; i++)
			{
			
			Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
			Quaternion spawnRotation = Quaternion.identity;
			Instantiate(hazard, spawnPosition, spawnRotation);
			yield return new WaitForSeconds (spawnWait);
		}
			yield return new WaitForSeconds (waveWait);

			if (gameOver)
			{
				restartText.text = "Press 'R' for Restart";
				restart = true;
				break;

			}
		}
	}
	public void AddScore (int newScoreValue)
	{
		score += newScoreValue;
		UpdateScore ();
	}

	void UpdateScore ()
	{
		scoreText.text = "Score: "  + score;
}
	public void GameOver ()
	{
		gameOverText.text = "Game Over!";
		gameOver = true;
	}
}

The gameOver comes from my DestroyOnContact script, which is the following

using UnityEngine;
using System.Collections;

public class DestroyByContact : MonoBehaviour
{
	public GameObject explosion;
	public GameObject playerexplosion;
	public int scoreValue;
	private GameController gameController;
	
	void Start ()
	{
		GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
		if (gameControllerObject != null)
		{
			gameController = gameControllerObject.GetComponent <GameController>();
		}
		if (gameController == null)
		{
			Debug.Log ("Cannot find 'GameController' script");
		}
	}
	
	void OnTriggerEnter(Collider other) 
	{
		if (other.tag == "Boundary")
		{
			return;
		}
		Instantiate(explosion, transform.position, transform.rotation);
		if (other.tag == "Player")
		{
			Instantiate(playerexplosion, other.transform.position, other.transform.rotation);
			gameController.GameOver ();
		}
		gameController.AddScore (scoreValue);
		Destroy(other.gameObject);
		Destroy(gameObject);
	}
}

It says that if it collides with the tag “Player”, then GameOver from gameController script should be true, right? Which should make the other script work.

Try changing update() to Update() in GameController.cs

You’re a lifesaver! I did not catch that typo, even though I looked at my scripts for hours last night.

Thanks for taking the time to look it through. I owe you :wink: