ok so this should be the way to go
This commit is contained in:
@@ -5,10 +5,8 @@ using Movementtests.interfaces;
|
||||
[GlobalClass]
|
||||
public partial class CHealth : Node, IHealthable
|
||||
{
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float health);
|
||||
[Signal]
|
||||
public delegate void DeadEventHandler();
|
||||
public event Action<IHealthable, float> HealthChanged;
|
||||
public event Action<IHealthable> HealthDepleted;
|
||||
|
||||
[Export]
|
||||
public RHealth HealthResource;
|
||||
@@ -20,15 +18,15 @@ public partial class CHealth : Node, IHealthable
|
||||
CurrentHealth = HealthResource.StartingHealth;
|
||||
}
|
||||
|
||||
public void ReduceHealth(float amount)
|
||||
public void ReduceHealth(IDamageable source, float amount)
|
||||
{
|
||||
CurrentHealth -= amount;
|
||||
EmitSignalHealthChanged(CurrentHealth);
|
||||
HealthChanged?.Invoke(this, CurrentHealth);
|
||||
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
CurrentHealth = 0;
|
||||
EmitSignalDead();
|
||||
HealthDepleted?.Invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user