using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class UIManager : MonoBehaviour { public Text coinText; // Элементы окна проигрыша public GameObject gameOverPanel; public Text finalScoreText; public Button restartButton; void Start() { // Подписываемся на событие смерти игрока PlayerController.OnPlayerDied += ShowGameOverScreen; // Скрываем панель проигрыша при старте if (gameOverPanel != null) { gameOverPanel.SetActive(false); } // Назначаем действие для кнопки if (restartButton != null) { restartButton.onClick.AddListener(RestartGame); } } void OnDestroy() { // ОБЯЗАТЕЛЬНО отписываемся от события, чтобы избежать ошибок PlayerController.OnPlayerDied -= ShowGameOverScreen; } void Update() { if (coinText != null) { coinText.text = "Монеты: " + PlayerController.coinCount; } } void ShowGameOverScreen() { if (gameOverPanel != null && finalScoreText != null) { gameOverPanel.SetActive(true); finalScoreText.text = "Ваш результат: " + PlayerController.coinCount; } } void RestartGame() { // Возобновляем время перед загрузкой сцены Time.timeScale = 1f; SceneManager.LoadScene(SceneManager.GetActiveScene().name); } }