From 92059d3620f5f6f2cb41fc8958c083f80bf4b15e Mon Sep 17 00:00:00 2001 From: Furentes Date: Thu, 11 Apr 2019 11:08:37 +0200 Subject: [PATCH] Added restart [F1] and exit game [ESC] --- Assets/Scripts/Spawner.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Spawner.cs b/Assets/Scripts/Spawner.cs index d161f35..7c5a54e 100644 --- a/Assets/Scripts/Spawner.cs +++ b/Assets/Scripts/Spawner.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using TMPro; using UnityEngine; +using UnityEngine.SceneManagement; using UnityEngine.UI; public class Spawner : MonoBehaviour @@ -15,10 +16,25 @@ public class Spawner : MonoBehaviour // Constructor (called when game starts) void Start() { + Group.fallSpeed = 1f; + Grid.count = 0; + score.text = "Score: " + Grid.count; // Spawn initial group spawnNext(); } + private void Update() + { + if (Input.GetKey(KeyCode.Escape)) + { + Application.Quit(); + } + if (Input.GetKey(KeyCode.F1)) + { + restart(); + } + } + public void spawnNext() { score.text = "Score: " + Grid.count; @@ -26,12 +42,10 @@ public class Spawner : MonoBehaviour int i = Random.Range(0, groups.Length); // Spawn group at current spawner position Instantiate(groups[i], transform.position, Quaternion.identity); - - if (Group.gameOver) gameOver(); } - public void gameOver() + void restart() { - score.text = "GAME OVER"; + SceneManager.LoadScene(SceneManager.GetActiveScene().name); } }