готово ко 2 кт
This commit is contained in:
1 parent
0f9a539460
commit
5bd4118b23
7 files changed
+796
-21
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
@@ -7,20 +9,81 @@ namespace _Project.Scripts.PlayerUtils
|
||||
[Header("Настройки Интерфейса")]
|
||||
[SerializeField] private bool showHUD = true;
|
||||
|
||||
[Header("Панель проигрыша (Canvas UI)")]
|
||||
[Tooltip("Перетащи сюда панель поражения из Canvas. Если пусто — отрисуется встроенная панель проигрыша.")]
|
||||
[SerializeField] private GameObject losePanel;
|
||||
|
||||
private PlayerMovement movement;
|
||||
private PlayerPossession possession;
|
||||
private bool isGameOver = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
movement = Player.Instance.Movement;
|
||||
possession = Player.Instance.Possession;
|
||||
|
||||
if (losePanel != null)
|
||||
{
|
||||
losePanel.SetActive(false);
|
||||
}
|
||||
|
||||
if (possession != null)
|
||||
{
|
||||
possession.OnPlayerDied += HandlePlayerDied;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (possession != null)
|
||||
{
|
||||
possession.OnPlayerDied -= HandlePlayerDied;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePlayerDied()
|
||||
{
|
||||
isGameOver = true;
|
||||
|
||||
if (losePanel != null)
|
||||
{
|
||||
losePanel.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Быстрый перезапуск по клавише R после смерти
|
||||
if (isGameOver && Keyboard.current != null && Keyboard.current.rKey.wasPressedThisFrame)
|
||||
{
|
||||
RestartLevel();
|
||||
}
|
||||
}
|
||||
|
||||
// Этот метод также можно повесить на кнопку (Button -> OnClick) на твоём Canvas!
|
||||
public void RestartLevel()
|
||||
{
|
||||
Time.timeScale = 1f;
|
||||
Time.fixedDeltaTime = 0.02f;
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
// 1. Если игрок погиб, а кастомная Canvas-панель не назначена — рисуем экран проигрыша
|
||||
if (isGameOver)
|
||||
{
|
||||
if (losePanel == null)
|
||||
{
|
||||
DrawFallbackLoseScreen();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Обычный боевой HUD
|
||||
if (!showHUD || movement == null) return;
|
||||
|
||||
float speed = movement.CurrentSpeed;
|
||||
float speed = movement.CurrentSpeed;
|
||||
float csUnits = speed * 38.5f;
|
||||
|
||||
GUIStyle style = new GUIStyle { fontSize = 22, fontStyle = FontStyle.Bold };
|
||||
@@ -56,5 +119,40 @@ namespace _Project.Scripts.PlayerUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawFallbackLoseScreen()
|
||||
{
|
||||
// Полупрозрачное тёмно-красное/чёрное затемнение на весь экран
|
||||
Color prevColor = GUI.color;
|
||||
GUI.color = new Color(0.08f, 0.01f, 0.02f, 0.85f);
|
||||
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Texture2D.whiteTexture);
|
||||
GUI.color = prevColor;
|
||||
|
||||
GUIStyle titleStyle = new GUIStyle
|
||||
{
|
||||
fontSize = 48,
|
||||
fontStyle = FontStyle.Bold,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
titleStyle.normal.textColor = new Color(1f, 0.2f, 0.25f);
|
||||
|
||||
GUIStyle subStyle = new GUIStyle
|
||||
{
|
||||
fontSize = 22,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
subStyle.normal.textColor = new Color(0.85f, 0.85f, 0.85f);
|
||||
|
||||
float cx = Screen.width / 2f;
|
||||
float cy = Screen.height / 2f;
|
||||
|
||||
GUI.Label(new Rect(cx - 300f, cy - 110f, 600f, 60f), "ДУХ МЩЕНИЯ РАЗВЕЯН", titleStyle);
|
||||
GUI.Label(new Rect(cx - 300f, cy - 45f, 600f, 40f), "Вы потеряли последнюю связь с этим миром.", subStyle);
|
||||
|
||||
if (GUI.Button(new Rect(cx - 150f, cy + 25f, 300f, 50f), "ПЕРЕЗАПУСТИТЬ ЭТАЖ [R]"))
|
||||
{
|
||||
RestartLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user