fix: players now take damage offline

This commit is contained in:
Chris
2025-12-05 20:37:46 -05:00
parent a0ed17666d
commit 7f3bfcffe7

View File

@@ -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) {