From 112a91b7084a5365291c712fabcb8ceeb4c644ce Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sun, 8 Oct 2017 22:43:20 +0200 Subject: Added game over screen --- td/Assets/Scripts/player.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'td/Assets/Scripts/player.cs') diff --git a/td/Assets/Scripts/player.cs b/td/Assets/Scripts/player.cs index c421720..a8106d3 100644 --- a/td/Assets/Scripts/player.cs +++ b/td/Assets/Scripts/player.cs @@ -6,7 +6,8 @@ public class Player : MonoBehaviour { public int InitialHealth; public int StartingMoney; - + public MainGui MainGui; + private GameObject[] _towers; private int _playerMoney; private int _playerScore; @@ -16,6 +17,7 @@ public class Player : MonoBehaviour { /* This method initializes the player class */ _playerMoney = StartingMoney; _playerHealth = InitialHealth; + InvokeRepeating ("GameStateWatcher", 0f, 0.5f); } #region stats @@ -43,9 +45,9 @@ public class Player : MonoBehaviour { return _playerHealth; } - public float HealthAsPercentage() + public int HealthAsPercentage() { - return InitialHealth / _playerHealth; + return Mathf.RoundToInt((InitialHealth * _playerHealth) / 100.0f); // Basic percentage calc... } public void DecreaseHealth(int hp) { @@ -59,4 +61,10 @@ public class Player : MonoBehaviour { script.Player = this; } + public void GameStateWatcher() { + if (_playerHealth <= 0) { + MainGui.GameOverScreen(_playerScore); + } + } + } -- cgit v1.2.3