씬 정리
This commit is contained in:
45
Assets/Scripts/Unicorn/LivingEntity.cs
Normal file
45
Assets/Scripts/Unicorn/LivingEntity.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Unicorn.Game.Hitbox;
|
||||
using UnityEngine;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace Unicorn.Game
|
||||
{
|
||||
public partial class LivingEntity : MonoBehaviour
|
||||
{
|
||||
private Rigidbody2D _rb;
|
||||
public float health = 20.0f;
|
||||
|
||||
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)
|
||||
{
|
||||
health -= info.damage;
|
||||
OnDamaged(info);
|
||||
if (health <= 0.0f) OnDeath();
|
||||
}
|
||||
|
||||
|
||||
protected virtual void OnDeath()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Rigidbody2D Rb => _rb;
|
||||
|
||||
protected virtual void OnDamaged(DamageInfo info)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user