using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class WinManager : MonoBehaviour
{
[Header("Ссылки на интерфейс")]
public GameObject winScreen; // Панель WinScreen
public Button mainMenuButton; // Кнопка MainMenuButton
private Image blackOverlay; // Компонент цвета панели для затемнения
private bool isWinning = false;
private float fadeTimer = 0f;
void Start()
{
if (winScreen != null)
{
winScreen.SetActive(false);
blackOverlay = winScreen.GetComponent<Image>();
}
if (mainMenuButton != null)
mainMenuButton.onClick.AddListener(GoToMenu);
}
void Update()
{
// Если Олег победил — плавно затягиваем экран чёрным цветом
if (isWinning && blackOverlay != null)
{
fadeTimer += Time.unscaledDeltaTime * 0.8f; // Скорость затемнения
Color c = blackOverlay.color;
c.a = Mathf.Clamp01(fadeTimer);
blackOverlay.color = c;
}
}
public void TriggerWin()
{
if (isWinning) return;
isWinning = true;
// Включаем панель, но делаем её изначально полностью прозрачной
if (winScreen != null)
{
winScreen.SetActive(true);
if (blackOverlay != null)
{
Color c = blackOverlay.color;
c.a = 0f;
blackOverlay.color = c;
}
// Временно прячем кнопку меню во время красивого ухода в чёрный
if (mainMenuButton != null) mainMenuButton.gameObject.SetActive(false);
}
// Отключаем шаги монстра, чтобы они не шумели в финале
MonsterAI monster = FindFirstObjectByType<MonsterAI>();
if (monster != null) monster.enabled = false;
// Через 2 секунды полностью останавливаем мир и показываем кнопку меню
Invoke("ShowMenuButton", 2.0f);
}
void ShowMenuButton()
{
Time.timeScale = 0f; // Замораживаем игру
Cursor.lockState = CursorLockMode.None; // Включаем мышку
Cursor.visible = true;
if (mainMenuButton != null) mainMenuButton.gameObject.SetActive(true);
}
void GoToMenu()
{
Time.timeScale = 1f;
SceneManager.LoadScene(0); // Возвращаемся в главное меню SlimUI
}
}