From fe8c8c3ef45c8ba697c5ddfe712d63c37a369f37 Mon Sep 17 00:00:00 2001 From: djkellerman Date: Mon, 17 Feb 2025 14:09:17 -0500 Subject: [PATCH] playerlives added basic playerlives counting for the free-for-all gamemode. Sstill needs to be implemented --- Assets/Scripts/Damageable.cs | 14 ++++++++++ Assets/Scripts/PlayerLives.cs | 43 ++++++++++++++++++++++++++++++ Assets/Scripts/PlayerLives.cs.meta | 2 ++ 3 files changed, 59 insertions(+) create mode 100644 Assets/Scripts/PlayerLives.cs create mode 100644 Assets/Scripts/PlayerLives.cs.meta diff --git a/Assets/Scripts/Damageable.cs b/Assets/Scripts/Damageable.cs index 13644d1..e3f4714 100644 --- a/Assets/Scripts/Damageable.cs +++ b/Assets/Scripts/Damageable.cs @@ -38,6 +38,20 @@ public class Damageable : MonoBehaviour } damage += actualForce; damage = Mathf.Clamp(damage, 0f, maxDamage); + + if (damage >= maxDamage) + { + Die(); + } + } + + private void Die() + { + PlayerLives playerLives = GetComponent(); //add death animation trigger + if (playerLives != null) + { + playerLives.PlayerDied(); + } } public void ResetDamage() diff --git a/Assets/Scripts/PlayerLives.cs b/Assets/Scripts/PlayerLives.cs new file mode 100644 index 0000000..0a35bd3 --- /dev/null +++ b/Assets/Scripts/PlayerLives.cs @@ -0,0 +1,43 @@ +using UnityEngine; + +public class PlayerLives : MonoBehaviour +{ + public int maxLives = 3; + public int currentLives; + public string gameMode = "free-for-all"; + + private void Start() + { + if (gameMode == "free-for-all") + { + currentLives = maxLives; + } + else //add more gamemodes and their lives here + { + currentLives = 0; + } + } + public void PlayerDied() + { + if (gameMode == "free-for-all") + { + currentLives--; + if (currentLives <= 0) + { + //add Game over sequence; + } + else + { + RespawnPlayer(); + } + } + } + private void RespawnPlayer() + { + RespawnOnTriggerEnter respawnScript = GetComponent(); + if (respawnScript != null) + { + transform.position = respawnScript.spawnPoint; + } + } +} diff --git a/Assets/Scripts/PlayerLives.cs.meta b/Assets/Scripts/PlayerLives.cs.meta new file mode 100644 index 0000000..d13c985 --- /dev/null +++ b/Assets/Scripts/PlayerLives.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 207bf152528fc954cb2c73fd9d62c9b0 \ No newline at end of file