I have a list of targets, that when their health float reaches zero, deletes itself and sends an event to which my “Gun” script subscribes.
public void Damage(float damage)
{
health -= damage;
if (health <= 0)
{
OnEnemyKilled?.Invoke(this, EventArgs.Empty);
source.PlayOneShot(kill, 0.25f);
Destroy(gameObject);
}
}
private void Target_OnEnemyKilled(object sender, EventArgs e)
{
AmmoRegen();
}
public void AmmoRegen()
{
if (this.gameObject.activeSelf)
{
gunData.currentAmmo = gunData.currentAmmo + gunData.magSize / 2;
gunData.currentAmmo = gunData.currentAmmo + 1;
if (gunData.currentAmmo > gunData.magSize)
gunData.currentAmmo = gunData.magSize + 1;
}
}
The GameObject deletion works fine but where I’m running into issues is getting to event to trigger on all objects with the “Target” script attached. Currently, the event will only trigger on a weapon with the “Gun” script attached if it destroys the one GameObject set as the “Target” within the “Gun” script.
![]()
![]()
I’ve used an array to grab all objects with a certain tag so that they become “Targetable”, but my question is how do I make the actual target variable use the array of “Targetable” GameObjects as the input, so that my weapon will receive the event when destroying all GameObjects in the array instead of on the one set as “Target”.
Essentially, how do I get this
![]()
to use this

as the “target” input.
