Space Shooter problems

I’m on step 16 of 17 (Ending the Game) of the Space Shooter tutorials and have run into my first issue with this tutorial series. Not bad considering, but I’d love to know why “Game Over” is prematurely appearing with the destruction of the first asteroid. I have a feeling that it has something to do with the instantiation of the asteroid, but can’t figure it out.

Another thing is that the ‘R’ key is not restarting the game. This isn’t a surprise since the asteroid waves never cease. Which is my last issue; the game won’t end.

I’m bug-eyed from comparing my code with what’s appearing in the tutorial. They seem to be identical … ??

::::::::::GameController Script::::::::::

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 bool gameOver;
	private bool restart;
	private int score;

	void Start () {
		gameOver = false;
		restart = false;
		restartText.text = "";
		gameOverText.text = "";
		score = 0;
		UpdateScore ();
		StartCoroutine (SpawnWaves ());

	void Update () {
		if (restart) {
			if (Input.GetKeyDown (KeyCode.R)) {
				Application.LoadLevel (Application.loadedLevel);

	IEnumerator SpawnWaves () {
		yield return new WaitForSeconds (startWait);
		for (int i =0; i < hazardCount; i++) {

			while (true) {
				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;

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

	void UpdateScore () {
		scoreText.text = "Score :: " + score;

	public void GameOver (){
		gameOverText.text = "Game Over!";
		gameOver = true;


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") {
		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);

Well, it seems that fixing the while loop earlier did make some progress after all. Everything works now (i.e. ‘R’ key resets the game, asteroids stop after the Player is killed, etc.,) except that destroying the first asteroid still prematurely invokes the "Game Over! "text.

I’ve gone line by line against the code in the video and can’t find a single character out of place.


I found an unnecessary semi-colon in one of my lines of code [line 26 above]. So, Thank you very much getyour411! Your suggestions prompted me to look closer at my code.