From 7f3bfcffe742274357735da253952829a3775bc0 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 5 Dec 2025 20:37:46 -0500 Subject: [PATCH] fix: players now take damage offline --- Assets/Scripts/Units/Player.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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) {