mirror of
https://github.com/ryzij/Cube-Tower-Defense.git
synced 2026-07-14 01:56:57 +00:00
Добавил возможность проиграть
This commit is contained in:
+22
-1
@@ -1,14 +1,29 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[RequireComponent(typeof(TowerHealth))]
|
||||
public class Tower : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private UnityEvent _onGameOver;
|
||||
|
||||
public event UnityAction OnGameOver
|
||||
{
|
||||
add => _onGameOver.AddListener(value);
|
||||
remove => _onGameOver.RemoveListener(value);
|
||||
}
|
||||
|
||||
private TowerHealth _towerHealth;
|
||||
|
||||
private void Start()
|
||||
private void OnEnable()
|
||||
{
|
||||
_towerHealth = GetComponent<TowerHealth>();
|
||||
_towerHealth.OnHealthChanged += OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_towerHealth.OnHealthChanged -= OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
@@ -16,4 +31,10 @@ public class Tower : MonoBehaviour
|
||||
if (other.TryGetComponent(out Enemy enemy))
|
||||
_towerHealth.TakeDamage(enemy.Damage);
|
||||
}
|
||||
|
||||
private void OnHealthChanged(TowerHealth.OnHealthChangedEventArgs args)
|
||||
{
|
||||
if (args.CurrentHealth <= 0)
|
||||
_onGameOver?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user