TMP는 깃에서 없애야 하는데 저 할 줄 모르니까 알아서 잘 해보시고 어자피 프로젝트 크기 5메가바이트도 안 넘으니까 굳이굳이 할 필요 없으심 즐 전 자러감ㅋㅋ
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using Unicorn.Hitbox;
|
|
using UnityEngine;
|
|
|
|
namespace Unicorn
|
|
{
|
|
public partial class LivingEntity : MonoBehaviour
|
|
{
|
|
public float health = 20.0f;
|
|
private Rigidbody2D Rb { get; set; }
|
|
private bool _invulnerable = false;
|
|
|
|
private void Start()
|
|
{
|
|
Rb = TryGetComponent(out Rigidbody2D rb) ? rb : null;
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (Rb == null) return;
|
|
var transformPosition = other.transform.position - transform.position;
|
|
Rb.linearVelocity = Vector2.zero;
|
|
Rb.AddForce(transformPosition.normalized * health, ForceMode2D.Impulse);
|
|
}
|
|
|
|
public void Damage(DamageInfo info)
|
|
{
|
|
if (_invulnerable) return;
|
|
health -= info.Damage;
|
|
OnDamaged(info);
|
|
if (health <= 0.0f) OnDeath();
|
|
}
|
|
|
|
|
|
protected virtual void OnDeath() { }
|
|
|
|
|
|
protected virtual void OnDamaged(DamageInfo info) { }
|
|
|
|
protected virtual void OnKnockback(DamageInfo info)
|
|
{
|
|
var dir = transform.position - info.HitPoint;
|
|
Rb.AddForce(dir.normalized * info.KnockbackForce, ForceMode2D.Impulse);
|
|
}
|
|
}
|
|
}
|