private void OnHit(UnitHitEvent unitHit) { if (GetParent().Name == unitHit.target.Name) { //Reduce the tanks health with the given amount health -= unitHit.damage; //Broadcast the health after it has been modified to anyone who is listening HealthEvent hei = new HealthEvent(); hei.health = health; hei.target = unitHit.target; hei.FireEvent(); //Check if the health has gone down to zero CheckHealth(); } }
public override void _ExitTree() { UnitHitEvent.UnregisterListener(OnHit); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { UnitHitEvent.RegisterListener(OnHit); }