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()
|
|
|
|
|
{
|
2021-01-11 13:42:43 +01:00
|
|
|
|
FMODUnity.RuntimeManager.PlayOneShot("event:/hit");
|
|
|
|
|
|
2021-01-05 13:10:20 +01:00
|
|
|
|
--lives;
|
|
|
|
|
if (lives > 0)
|
|
|
|
|
{
|
|
|
|
|
OnDie?.Invoke(lives);
|
|
|
|
|
_health.Reset();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
OnGameOver?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|