// Called when the node enters the scene tree for the first time. public override void _Ready() { healthbar = GetNode <TextureProgress>("Health"); ammobar = GetNode <TextureProgress>("Ammo"); SendHealthEvent.RegisterListener(UpdateHealth); SendAmmoEvent.RegisterListener(UpdateAmmo); }
private void OnHit(HitEvent hei) { if (GetParent().Name == hei.target.Name) { //Reduce the tanks health with the given amount health -= hei.damage; //Check if the health has gone down to zero CheckHealth(); if (hei.target.IsInGroup("Player")) { //Broadcast the health after it has been modified to anyone who is listening SendHealthEvent shei = new SendHealthEvent(); shei.health = health; shei.target = hei.target; shei.FireEvent(); } } }
public override void _ExitTree() { SendHealthEvent.UnregisterListener(UpdateHealth); SendAmmoEvent.UnregisterListener(UpdateAmmo); }
private void UpdateHealth(SendHealthEvent shei) { healthbar.Value = shei.health; }