Since the only answer for my question is from Unity 4 it’s not sufficient. What I need is a Current line for the code i have to make my game Restart when I press the R button. There is another problem my " Press R to restart " text is not showing up in the game after i blow myself up. Here’s the Code, i have several Other Scripts too that this one Calls out to.
using UnityEngine;
using UnityEngine.SceneManagement;
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 Update ()
{
if (restart)
{
if (Input.GetKeyDown (KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}
void Start()
{
gameOver = false;
restart = false;
gameOverText.text = "";
restartText.text = "";
StartCoroutine (SpawnWaves ());
score = 0;
UpdateScore ();
}
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 == true)
{
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;
}
}
Are you using void OnGUI for your GUIText?
– SonicScrew12