Add new meta files and interfaces for project structure
This commit is contained in:
36
Assets/Scripts/Systems/DeathHandler.cs
Normal file
36
Assets/Scripts/Systems/DeathHandler.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Data;
|
||||
using Interfaces;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class DeathHandler : MonoBehaviour
|
||||
{
|
||||
[Self, SerializeField] private Character character;
|
||||
[Self, SerializeField] private InterfaceRef<IDeathBehavior> deathBehavior;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
character.attributes.OnHealthChanged += OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
character.attributes.OnHealthChanged -= OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnHealthChanged(float newHealth)
|
||||
{
|
||||
if (newHealth <= 0f)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
deathBehavior.Value.Die();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user