какашки мне в кармашки
This commit is contained in:
1 parent
7fba61f7a0
commit
cbda26dfc0
335 files changed
+51926
-7266
No files matched your search
@@ -1,29 +1,101 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerHealth : MonoBehaviour
|
||||
{
|
||||
public float maxHealth = 100f;
|
||||
private float currentHealth;
|
||||
private float currentHealth = 100f;
|
||||
|
||||
public bool IsDead => currentHealth <= 0;
|
||||
public float CurrentHealth => currentHealth;
|
||||
|
||||
[Header("Компоненты персонажа (автоматически)")]
|
||||
public Animator playerAnimator;
|
||||
public CharacterController characterController;
|
||||
public PlayerMovement playerMovement;
|
||||
public PlayerGun playerGun;
|
||||
public PlayerAttack playerAttack;
|
||||
public EchoTrigger echoTrigger;
|
||||
|
||||
[Header("Экран смерти")]
|
||||
public DeathScreenUI deathScreenUI;
|
||||
[Tooltip("Пауза перед показом экрана смерти для проигрывания анимации падения")]
|
||||
public float deathScreenDelay = 1.2f;
|
||||
|
||||
[Header("Защита от мгновенного урона толпой")]
|
||||
[Tooltip("Минимальная задержка между получением урона от ударов врагов")]
|
||||
public float damageCooldown = 0.35f;
|
||||
private float lastDamageTime = -10f;
|
||||
|
||||
private bool hasDied = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
|
||||
if (playerAnimator == null) playerAnimator = GetComponentInChildren<Animator>();
|
||||
if (characterController == null) characterController = GetComponent<CharacterController>();
|
||||
if (playerMovement == null) playerMovement = GetComponent<PlayerMovement>();
|
||||
if (playerGun == null) playerGun = GetComponent<PlayerGun>();
|
||||
if (playerAttack == null) playerAttack = GetComponent<PlayerAttack>();
|
||||
if (echoTrigger == null) echoTrigger = GetComponent<EchoTrigger>();
|
||||
if (deathScreenUI == null) deathScreenUI = FindAnyObjectByType<DeathScreenUI>();
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
if (IsDead) return;
|
||||
if (IsDead || hasDied) return;
|
||||
if (Time.time < lastDamageTime + damageCooldown) return;
|
||||
lastDamageTime = Time.time;
|
||||
|
||||
currentHealth -= damage;
|
||||
Debug.Log($"Игрок получил урон! Осталось здоровья: {currentHealth}");
|
||||
|
||||
if (currentHealth <= 0)
|
||||
if (currentHealth <= 0f)
|
||||
{
|
||||
Debug.Log("ИГРОК МЕРТВ! Конец игры.");
|
||||
// Здесь позже можно будет добавить перезагрузку уровня
|
||||
currentHealth = 0f;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
if (hasDied) return;
|
||||
hasDied = true;
|
||||
Debug.Log("<color=red>[PlayerHealth] ИГРОК ПОГИБ! Запуск экрана смерти.</color>");
|
||||
|
||||
// Отключаем управление и физику персонажа
|
||||
if (playerMovement != null) playerMovement.enabled = false;
|
||||
if (playerGun != null) playerGun.enabled = false;
|
||||
if (playerAttack != null) playerAttack.enabled = false;
|
||||
if (echoTrigger != null) echoTrigger.enabled = false;
|
||||
if (characterController != null) characterController.enabled = false;
|
||||
|
||||
// Отключаем слой удержания оружия и запускаем анимацию смерти
|
||||
if (playerAnimator != null)
|
||||
{
|
||||
if (playerAnimator.layerCount > 1)
|
||||
{
|
||||
playerAnimator.SetLayerWeight(1, 0f);
|
||||
}
|
||||
playerAnimator.SetTrigger("Die");
|
||||
}
|
||||
|
||||
// Показываем экран смерти с кинематографичной задержкой
|
||||
StartCoroutine(ShowDeathScreenDelayed());
|
||||
}
|
||||
|
||||
private IEnumerator ShowDeathScreenDelayed()
|
||||
{
|
||||
yield return new WaitForSeconds(deathScreenDelay);
|
||||
|
||||
if (deathScreenUI != null)
|
||||
{
|
||||
deathScreenUI.ShowDeathScreen();
|
||||
}
|
||||
else if (DeathScreenUI.Instance != null)
|
||||
{
|
||||
DeathScreenUI.Instance.ShowDeathScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user