Shoot-N-Slash/Assets/Scripts/Entity.cs

48 lines
1 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
public class Entity : MonoBehaviour
{
[Header("Health")]
public float health;
public float maxHealth;
[Header("Stats")]
public float speed;
public float jumpPower;
[Header("Abilities")]
public List<Ability> abilities = new();
public Transform attackOriginPoint;
[SerializeField] protected Transform attackOriginCenter;
[Header("Cache")]
[SerializeField] protected Rigidbody2D rb;
public List<Entity> entitiesInRange = new();
public Entity closestEntity;
[Header("Ground Detection")]
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;
public void TakeDamage(float damage)
{
health -= damage;
if (health <= 0)
{
OnDeath();
}
}
public void Heal(float healing)
{
health += healing;
health = Math.Clamp(health, 0, maxHealth);
}
protected virtual void OnDeath()
{
}
protected bool OnGround()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.05f, groundLayer);
}
}