MarisaMagicalStudy/Assets/Scripts/Entity.cs
2026-01-29 01:49:09 -08:00

59 lines
1.4 KiB
C#

using UnityEngine;
public class Entity : MonoBehaviour
{
[Header("Identification")]
public string entityName;
public SpriteRenderer sprite;
[Header("Flags")]
public bool stalled;
public bool invincible;
[Header("Stats")]
public float health;
public float maxHealth;
[Header("Movement")]
[SerializeField] private bool isFacingRight;
[SerializeField] protected Rigidbody2D rb;
protected Vector2 moveDirection;
public float speed;
protected void FlipSprite(Vector2 lookDirection)
{
if (lookDirection.x < 0f && isFacingRight)
{
sprite.flipX = true;
isFacingRight = !isFacingRight;
}
else if (lookDirection.x > 0f && !isFacingRight)
{
sprite.flipX = false;
isFacingRight = !isFacingRight;
}
}
protected virtual void FixedUpdate()
{
if (!stalled)
{
rb.linearVelocity = moveDirection * speed;
}
}
public void TakeDamage(float damage)
{
health -= damage;
health = Mathf.Clamp(health, 0, maxHealth);
if (health < 0)
{
OnKillEffects();
}
}
public void Heal(float healingAmount)
{
health += healingAmount;
health = Mathf.Clamp(health, 0, maxHealth);
}
protected virtual void OnKillEffects()
{
}
}