diff --git a/Assets/Scripts/Units/Player.cs b/Assets/Scripts/Units/Player.cs index fa61dc8..6df5e68 100644 --- a/Assets/Scripts/Units/Player.cs +++ b/Assets/Scripts/Units/Player.cs @@ -8,6 +8,7 @@ using Unity.Netcode; namespace Reset.Units{ public class Player : Unit, IKillable, IInteractable{ // IKillable + [ShowInInspector] public float maxHealth{ get; set; } public float currentHealth{ get; set; } @@ -32,7 +33,7 @@ namespace Reset.Units{ public float lastKnownReviveTime; void Awake(){ - maxHealth = 20f; + } void AttachToGame(){ @@ -83,20 +84,27 @@ namespace Reset.Units{ // Tell every unit to set the new health value if (UnitIsNetworked()) { SetHealthRpc(newHealth); + } else { + SetHealth(newHealth); } } [Rpc(SendTo.Everyone)] public void SetHealthRpc(float health){ // Set health to new value, clamped to 0 - health = Mathf.Max(health, 0f); - currentHealth = health; - + SetHealth(health); + // For local players, run things based on health value. // This Rpc is global but only the owner checks health CheckHealth(); } + private void SetHealth(float health){ + + health = Mathf.Max(health, 0f); + currentHealth = health; + } + void CheckHealth(){ if (UnitIsLocal()){ if (currentHealth <= 0f) {