// 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 AddAmmo(TileDestroyEvent tdei) { //Check if the tile destroyed bool is true if (tdei.tileDestroyed) { //Add ammo if a tile was destroyed ammo++; } else { if (ammo > 0) { //Create a ne bullet bullet = bulletScene.Instance(); //Set the direction of the bullet when instanced AddChild(bullet); ammo--; } } SendAmmoEvent saei = new SendAmmoEvent(); saei.ammo = ammo; saei.FireEvent(); }
public override void _ExitTree() { SendHealthEvent.UnregisterListener(UpdateHealth); SendAmmoEvent.UnregisterListener(UpdateAmmo); }
private void UpdateAmmo(SendAmmoEvent saei) { ammobar.Value = saei.ammo; }