Files
Memory-Defense/Assets/Scripts/LivingEntity.cs

26 lines
526 B
C#
Raw Normal View History

using System;
using UnityEngine;
2026-04-18 17:30:41 +09:00
public abstract class LivingEntity : MonoBehaviour
{
public float health;
2026-04-18 17:30:41 +09:00
protected abstract void OnDamaged(float damage);
public void Damage(float amount)
{
2026-04-18 17:30:41 +09:00
OnDamaged(amount);
health -= amount;
if (health <= 0)
{
Destroy(gameObject);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.layer == LayerMask.NameToLayer("Bullet"))
{
2026-04-18 17:30:41 +09:00
Damage(5);
}
}
}