diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 7d99184..a4c75a7 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -69,7 +69,14 @@ public class Character : MonoBehaviour characterAnimator = GetComponentInChildren(); } - + private void Update() + { + if(lives < 1) + { + this.enabled = false; + gameObject.SetActive(false); + } + } #endregion Unity Functions diff --git a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs index 7a07b56..2a2708c 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/ColorGameMode.cs @@ -170,15 +170,15 @@ public class ColorGameMode : GameMode { character.stuck = true; } - + Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); + } + protected override void OnPlayerKilled(Character character, ClientData client) + { if (character.inPit) { character.lives -= 1; character.ClientLink.Lives = character.lives; } - - Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); - } private IEnumerator AnimateBlock(Material mat, float time) diff --git a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs index 21a2bf0..e4ef42a 100644 --- a/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs +++ b/Assets/Scripts/GameMode/ColorGameMode/RacetrackGameMode.cs @@ -187,15 +187,16 @@ public class RacetrackGameMode : GameMode { character.stuck = true; } + Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); + } + protected override void OnPlayerKilled(Character character, ClientData client) + { if (character.inPit) { character.lives -= 1; character.ClientLink.Lives = character.lives; } - - Debug.Log("inWater = " + character.inWater + ", inPit = " + character.inPit + ", stuck = " + character.stuck); - } private IEnumerator AnimateBlock(Material mat, float time) diff --git a/Assets/Scripts/GameMode/GameMode.cs b/Assets/Scripts/GameMode/GameMode.cs index a8e3902..b813f02 100644 --- a/Assets/Scripts/GameMode/GameMode.cs +++ b/Assets/Scripts/GameMode/GameMode.cs @@ -67,6 +67,9 @@ public abstract class GameMode : ScriptableObject /// Block which the character finished on protected virtual void OnPlayerMoved(Character character, ClientData client, Block currentBlock) { } + + protected virtual void OnPlayerKilled(Character character, ClientData client) { } + /// /// Called once after every player has finished one move /// @@ -150,6 +153,11 @@ public abstract class GameMode : ScriptableObject OnPlayerMoved(player.character, player.client, player.character.CurrentBlock); } + public void PlayerKilled(PlayerData player) + { + OnPlayerKilled(player.character, player.client); + } + public void AllPlayersMoved(PlayerData[] allPlayers) { OnAllPlayersMoved(allPlayers); diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 63d5008..0e498ef 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -126,6 +126,12 @@ public class GameManager : MonoBehaviour //Let Gamemode know all players have moved gameMode.AllPlayersMoved(playerDataAsArray.ToArray()); + //decrease lives here!! + foreach(PlayerData player in playerDataAsArray) + { + gameMode.PlayerKilled(player); + } + playerDataAsArray.ForEach(p => p.client.SendLives()); //Update the players score //if Game is over break out of loop diff --git a/Assets/Scripts/Networking/Client/ClientLoginManager.cs b/Assets/Scripts/Networking/Client/ClientLoginManager.cs index 144e4e4..2cc1817 100644 --- a/Assets/Scripts/Networking/Client/ClientLoginManager.cs +++ b/Assets/Scripts/Networking/Client/ClientLoginManager.cs @@ -47,6 +47,7 @@ namespace Networking.Client [Tooltip("Send prefilled Player settings after connecting")] private bool IdentifyOnConnect = false; + ConnectedClients clients; #endregion Inspector Fields #region Events diff --git a/Assets/Scripts/UI/Client/LoginUIManager.cs b/Assets/Scripts/UI/Client/LoginUIManager.cs index 79e76d0..98d7460 100644 --- a/Assets/Scripts/UI/Client/LoginUIManager.cs +++ b/Assets/Scripts/UI/Client/LoginUIManager.cs @@ -8,7 +8,7 @@ public class LoginUIManager : MonoBehaviour { public int conn; public int maxPlayers = 2; - ConnectedClients clients; + public ConnectedClients clients; [Header("References")] [SerializeField] private ClientLoginManager clientManager; @@ -54,6 +54,15 @@ public class LoginUIManager : MonoBehaviour private void Update() { conn = GetComponent().count; + clients = GetComponent().Clients; + foreach (ClientData cli in clients.AllClients) + { + if (playerAnimal == cli.characterAnimal) + { + playerAnimal = null; + animalSelected = false; + } + } } private void OnEnable() { @@ -78,7 +87,6 @@ public class LoginUIManager : MonoBehaviour OnLoginFail(); } - #endregion Unity Functions @@ -151,6 +159,7 @@ public class LoginUIManager : MonoBehaviour { if (colorSelected == true && animalSelected == true && playerName != "") { + clientManager.SendPlayerDetails(playerName, playerColor, playerAnimal); PlayerPrefs.SetString("LastUsedName", playerName); }