diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-08 22:43:20 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2017-10-08 22:43:20 +0200 |
commit | 112a91b7084a5365291c712fabcb8ceeb4c644ce (patch) | |
tree | 54edd59c73ae7a5e435ff1c338c4384be73397cc /td/Assets/Scripts/player.cs | |
parent | 2338b4e43c35dd1990db69da5751bb28a9c4122c (diff) | |
download | TD-112a91b7084a5365291c712fabcb8ceeb4c644ce.tar.gz TD-112a91b7084a5365291c712fabcb8ceeb4c644ce.zip |
Added game over screen
Diffstat (limited to 'td/Assets/Scripts/player.cs')
-rw-r--r-- | td/Assets/Scripts/player.cs | 14 |
1 files changed, 11 insertions, 3 deletions
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); + } + } + } |