Files
Kursach_StealthAction/Assets/Scripts/MutantHealth.cs
T

37 lines
884 B
C#
Raw Normal View History

2026-10-19 20:14:24 +03:00
using UnityEngine;
2026-10-11 19:16:11 +03:00
public class MutantHealth : MonoBehaviour
2026-10-11 19:15:15 +03:00
{
2026-10-11 19:16:11 +03:00
public float maxHealth = 50f;
private float currentHealth;
2026-10-19 20:14:24 +03:00
public bool IsDead => currentHealth <= 0;
public float CurrentHealth => currentHealth;
2026-10-11 19:16:11 +03:00
2026-10-19 20:14:24 +03:00
private BlindMutantAI mutantAI;
void Awake()
2026-10-11 19:15:15 +03:00
{
2026-10-19 20:14:24 +03:00
currentHealth = maxHealth;
mutantAI = GetComponent<BlindMutantAI>();
}
public void TakeDamage(float damage, Transform attacker = null)
{
if (IsDead) return;
2026-10-11 19:16:11 +03:00
currentHealth -= damage;
2026-10-19 20:14:24 +03:00
Debug.Log($"Мутант получил урон: {damage}! Осталось: {currentHealth}");
if (mutantAI != null && attacker != null)
{
mutantAI.OnDamagedByPlayer(attacker);
}
2026-10-11 19:16:11 +03:00
if (currentHealth <= 0)
{
Debug.Log("МУТАНТ УМЕР!");
2026-10-19 20:14:24 +03:00
Destroy(gameObject);
2026-10-11 19:16:11 +03:00
}
2026-10-11 19:15:15 +03:00
}
}