using System;
using UnityEngine;

public abstract class LivingEntity : MonoBehaviour
{
    public float health;

    protected abstract void OnDamaged(float damage);
    public void Damage(float amount)
    {
        OnDamaged(amount);
        health -= amount;
        if (health <= 0)
        {
            Destroy(gameObject);
        }
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("Bullet"))
        {
            Damage(5);
        }
    }
}
