Ah sorry, thanks, I only read the title of the post, and looked at the reply marked “solved by”, and the rest of the replies. I have since used:
public event Action<int> OnTakeDamage;
public void TakeDamage(GameObject _instigator, int amount)
{
currentHealth.value = Mathf.Max(currentHealth.value - amount, 0);
if (!triggeredDeath) OnTakeDamage?.Invoke(amount);
HandleDeath(_instigator);
}
in the health component, and
void Awake()
{
health = GetComponentInParent<Health>();
}
void OnEnable()
{
health.OnTakeDamage += Spawn;
}
private void OnDisable()
{
health.OnTakeDamage -= Spawn;
}
public void Spawn(int _damageAmount)
{
DamageText instance = Instantiate<DamageText>(damageTextPrefab, transform);
instance.SetValue(_damageAmount);
}
in the damage text spawner.
Thanks for your help once again!