hey im doing the space shooter tutorial and cant seem to get my game to restart when i press the R key.
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;
public bool gameOver;
public 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 ()
{
while (true)
{
for (int i = 0; i < hazardcount; i++)
{
yield return new WaitForSeconds(StartWait);
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' to 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;
}
}