lucid-super-dream/Assets/Scripts/EntityLives.cs

42 lines
756 B
C#
Raw Normal View History

2021-01-05 13:10:20 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Weapons.Scripts;
public class EntityLives : MonoBehaviour
{
[SerializeField] private int lives = 3;
public IntEvent OnDie;
public UnityEvent OnGameOver;
private EntityHealth _health;
private void Awake()
{
_health = GetComponent<EntityHealth>();
}
private void OnEnable()
{
_health.Die += Die;
}
private void OnDisable()
{
_health.Die -= Die;
}
private void Die()
{
--lives;
if (lives > 0)
{
OnDie?.Invoke(lives);
_health.Reset();
}
else
OnGameOver?.Invoke();
}
}