/
Lexan97
/
Cowbeat
Обзор
Документация
Войти
/
Lexan97
/
Cowbeat
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/Managers/LevelManager.cs
80 строк
2 KB
Lexa97
Final Commit gor present
26 май 2026, 23:40
26 май 2026, 23:40
70e9bdb
Код
Авторство
О чём код?
using UnityEngine; using TMPro; using UnityEngine.SceneManagement; public class LevelManager : MonoBehaviour { public static LevelManager Instance; [Header("UI")] public TextMeshProUGUI timerText; public TextMeshProUGUI enemiesText; [Header("Victory Screen")] [SerializeField] private GameObject victoryCanvas; [SerializeField] private TextMeshProUGUI finalTimeText; private float timer = 0f; private int enemiesLeft = 0; private bool isGameRunning = true; void Awake() { Instance = this; } void Start() { enemiesLeft = Object.FindObjectsByType<EnemyHealth>(FindObjectsSortMode.None).Length; if (victoryCanvas != null) victoryCanvas.SetActive(false); UpdateUI(); } void Update() { if (!isGameRunning) return; if (Time.timeScale > 0) { timer += Time.deltaTime; UpdateUI(); } } public void OnEnemyDied() { enemiesLeft--; UpdateUI(); if (enemiesLeft <= 0) WinGame(); } void UpdateUI() { if (timerText != null) timerText.text = $"{timer:F1}s"; if (enemiesText != null) enemiesText.text = $"Bandits remaining: {enemiesLeft}"; } void WinGame() { isGameRunning = false; if (victoryCanvas != null) { victoryCanvas.SetActive(true); if (finalTimeText != null) finalTimeText.text = $"{timer:F1} sec."; } Time.timeScale = 0f; Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } public void RestartGame() { Time.timeScale = 1f; SceneManager.LoadScene(SceneManager.GetActiveScene().name); } public void ExitToMenu() { Time.timeScale = 1f; SceneManager.LoadScene("MainMenu"); } }