For the TakeDamage method I’m confused what int Damage is doing. How is it getting its value?
public class Health : MonoBehaviour
{
[SerializeField] private int health = 100;
private void OnTriggerEnter2D(Collider2D other)
{
DamageDealer damageDealer = other.GetComponent<DamageDealer>();
if (damageDealer != null)
{
TakeDamage(damageDealer.GetDamage());
damageDealer.Hit();
}
}
void TakeDamage(int damage)
{
health -= damage;
if (health <= 0)
{
Destroy(gameObject);
}
}
}