- Home /
Space Shooter Tutorial: Issues in "Ending the game" step
I've been doing the space shooter tutorial, and it's gone well up to this point. I'm having issues with the game controller script. the values for gameOverText and restartText don't come up in the inspector, as well as it giving an error for "unexpected symbol 'restart'". Here is my game controller script, i can't see what's wrong with it.
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);
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 newScoreVaue)
{
score += newScoreVaue;
UpdateScore ();
}
void UpdateScore ()
{
scoreText.text = "Score: " + score;
}
public void GameOver ()
{
gameOverText.text = "Game Over!";
gameOver = true;
}
}
any help would be appreciated.
Answer by rutter · Mar 03, 2014 at 10:57 PM
Welcome to Unity Answers!
For future reference, it's usually best to include the full and exact text of any compiler error; you may not understand it, but it has meaning to us!
In your case, you're missing some semicolons:
gameOver = false
restart = false
Each statement must end with a semicolon. If you're keeping your code organized, this usually means a semicolon at the end of every line that "does something":
gameOver = false;
restart = false;
I didn't spot any other errors, right off, but I'm not at a machine to test right now.