From d77cd51742cb760f5f2e8f5f3c283e311ffffe1c Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Fri, 13 Oct 2017 22:11:33 +0200 Subject: Added new method for pausing the game --- td/Assets/Prefabs/Enemies/Enemy.prefab | Bin 7968 -> 7968 bytes td/Assets/Scenes/Level 1.unity | Bin 121672 -> 122396 bytes td/Assets/Scripts/Enemy.cs | 2 ++ td/Assets/Scripts/EnemySpawner.cs | 1 + td/Assets/Scripts/cameraHandler.cs | 3 +++ td/Assets/Scripts/mainGUI.cs | 20 ++++++++++++++------ td/Assets/Scripts/player.cs | 23 +++++++++++++++++++---- td/Assets/Scripts/waveSpawner.cs | 3 +-- 8 files changed, 40 insertions(+), 12 deletions(-) (limited to 'td') diff --git a/td/Assets/Prefabs/Enemies/Enemy.prefab b/td/Assets/Prefabs/Enemies/Enemy.prefab index 212a232..ed40756 100644 Binary files a/td/Assets/Prefabs/Enemies/Enemy.prefab and b/td/Assets/Prefabs/Enemies/Enemy.prefab differ diff --git a/td/Assets/Scenes/Level 1.unity b/td/Assets/Scenes/Level 1.unity index d83c9e7..e93598e 100644 Binary files a/td/Assets/Scenes/Level 1.unity and b/td/Assets/Scenes/Level 1.unity differ diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs index 3074003..20436db 100644 --- a/td/Assets/Scripts/Enemy.cs +++ b/td/Assets/Scripts/Enemy.cs @@ -17,6 +17,8 @@ public class Enemy : MonoBehaviour { private int _waypointNum = -1; // Using minus one so that first addition returns 0, first element in array void Update () { + if (Player.GameIsPaused()) { return; } // This ensures that the game stays paused + if ( (transform.position == _waypointPos && _waypointNum + 1 < Waypoints.Count) || _waypointNum == -1) { _waypointNum++; _waypointPos = new Vector3 (Waypoints [_waypointNum].x, 0.483f, Waypoints [_waypointNum].z); diff --git a/td/Assets/Scripts/EnemySpawner.cs b/td/Assets/Scripts/EnemySpawner.cs index 5b0249d..a1a6b1f 100644 --- a/td/Assets/Scripts/EnemySpawner.cs +++ b/td/Assets/Scripts/EnemySpawner.cs @@ -28,6 +28,7 @@ public class EnemySpawner : MonoBehaviour { } void Update () { + if (Player.GameIsPaused()) { return; } // This ensures that the game stays paused _n++; if (_n == _next) { diff --git a/td/Assets/Scripts/cameraHandler.cs b/td/Assets/Scripts/cameraHandler.cs index 1655509..7c2f75f 100644 --- a/td/Assets/Scripts/cameraHandler.cs +++ b/td/Assets/Scripts/cameraHandler.cs @@ -11,6 +11,8 @@ public class CameraHandler : MonoBehaviour { public static readonly float[] BoundsY = new float[]{-5f, 10f}; public static readonly float[] BoundsZ = new float[]{-8f, 8f}; public static readonly float[] ZoomBounds = new float[]{1f, 5f}; + [Header("Scripting vars")] + public Player Player; // Reference to the player object, should be set in designer private Camera _cam; @@ -26,6 +28,7 @@ public class CameraHandler : MonoBehaviour { } void Update() { + if (Player.GameIsPaused()) { return; } // If there's an open menu, or the clicker is being pressed, ignore the touch. /* if (GameManager.Instance.MenuManager.HasOpenMenu || GameManager.Instance.BitSpawnManager.IsSpawningBits) { diff --git a/td/Assets/Scripts/mainGUI.cs b/td/Assets/Scripts/mainGUI.cs index 35d3948..26ec78b 100644 --- a/td/Assets/Scripts/mainGUI.cs +++ b/td/Assets/Scripts/mainGUI.cs @@ -1,8 +1,12 @@ using System; using UnityEngine.UI; +using UnityEngine.SceneManagement; using UnityEngine; public class MainGui : MonoBehaviour { + [Header("Scripting vars")] + public Player Player; // Reference to the player object, should be set in designer + private GameObject _pnlMenu; private GameObject _pnlSidebar; private GameObject _pnlSettings; @@ -42,8 +46,8 @@ public class MainGui : MonoBehaviour { _btnSettings = _pnlMenu.transform.Find ("settings").gameObject.GetComponent