using UnityEngine; public class MutantHealth : MonoBehaviour { public float maxHealth = 50f; private float currentHealth; public bool IsDead => currentHealth <= 0; public float CurrentHealth => currentHealth; public System.Action OnHealthChanged; public System.Action OnDied; private BlindMutantAI mutantAI; void Awake() { currentHealth = maxHealth; mutantAI = GetComponent(); } public void SetMaxHealthForTest(float val) { maxHealth = val; currentHealth = val; } public void TakeDamage(float damage, Transform attacker = null) { if (IsDead) return; currentHealth -= damage; Debug.Log($"Мутант получил урон: {damage}! Осталось: {currentHealth}"); OnHealthChanged?.Invoke(currentHealth, maxHealth); if (mutantAI != null && attacker != null) { mutantAI.OnDamagedByPlayer(attacker); } if (currentHealth <= 0) { Die(); } } private void Die() { Debug.Log("МУТАНТ УМЕР!"); OnDied?.Invoke(); var anim = GetComponentInChildren(); if (anim != null) { anim.SetBool("IsDead", true); anim.SetTrigger("Die"); } if (mutantAI != null) { mutantAI.enabled = false; } var agent = GetComponent(); if (agent != null) { agent.isStopped = true; agent.enabled = false; } var col = GetComponent(); if (col != null) { col.enabled = false; } if (Application.isPlaying) { Destroy(gameObject, 3.5f); } } }