fix: players now take damage offline
This commit is contained in:
@@ -8,6 +8,7 @@ using Unity.Netcode;
|
|||||||
namespace Reset.Units{
|
namespace Reset.Units{
|
||||||
public class Player : Unit, IKillable, IInteractable{
|
public class Player : Unit, IKillable, IInteractable{
|
||||||
// IKillable
|
// IKillable
|
||||||
|
[ShowInInspector]
|
||||||
public float maxHealth{ get; set; }
|
public float maxHealth{ get; set; }
|
||||||
public float currentHealth{ get; set; }
|
public float currentHealth{ get; set; }
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ namespace Reset.Units{
|
|||||||
public float lastKnownReviveTime;
|
public float lastKnownReviveTime;
|
||||||
|
|
||||||
void Awake(){
|
void Awake(){
|
||||||
maxHealth = 20f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttachToGame(){
|
void AttachToGame(){
|
||||||
@@ -83,20 +84,27 @@ namespace Reset.Units{
|
|||||||
// Tell every unit to set the new health value
|
// Tell every unit to set the new health value
|
||||||
if (UnitIsNetworked()) {
|
if (UnitIsNetworked()) {
|
||||||
SetHealthRpc(newHealth);
|
SetHealthRpc(newHealth);
|
||||||
|
} else {
|
||||||
|
SetHealth(newHealth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Rpc(SendTo.Everyone)]
|
[Rpc(SendTo.Everyone)]
|
||||||
public void SetHealthRpc(float health){
|
public void SetHealthRpc(float health){
|
||||||
// Set health to new value, clamped to 0
|
// Set health to new value, clamped to 0
|
||||||
health = Mathf.Max(health, 0f);
|
SetHealth(health);
|
||||||
currentHealth = health;
|
|
||||||
|
|
||||||
// For local players, run things based on health value.
|
// For local players, run things based on health value.
|
||||||
// This Rpc is global but only the owner checks health
|
// This Rpc is global but only the owner checks health
|
||||||
CheckHealth();
|
CheckHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetHealth(float health){
|
||||||
|
|
||||||
|
health = Mathf.Max(health, 0f);
|
||||||
|
currentHealth = health;
|
||||||
|
}
|
||||||
|
|
||||||
void CheckHealth(){
|
void CheckHealth(){
|
||||||
if (UnitIsLocal()){
|
if (UnitIsLocal()){
|
||||||
if (currentHealth <= 0f) {
|
if (currentHealth <= 0f) {
|
||||||
|
|||||||
Reference in New Issue
Block a user