using UnityEngine; using TMPro; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { public float timeLeft = 999f; public TMP_Text timeText; public TMP_Text scoreText; public TMP_Text resultText; public GameObject restartButton; public AudioSource audioSource; public AudioClip loseSound; private int score = 0; private bool gameEnded = false; void Awake() { Time.timeScale = 1f; gameEnded = false; restartButton.SetActive(false); UpdateUI(); } void Update() { if (gameEnded) return; // Таймер /* timeLeft -= Time.deltaTime; timeText.text = "Time: " + Mathf.Ceil(timeLeft); if (timeLeft <= 0) { EndGame(true); } */ } // Добавление очков public void AddScore(int amount) { score += amount; scoreText.text = "Score: " + score; } // Конец игры public void EndGame(bool win) { gameEnded = true; Time.timeScale = 0f; resultText.text = win ? "Победа!" : "Поражение"; if (audioSource != null && loseSound != null) { audioSource.PlayOneShot(loseSound); } restartButton.SetActive(true); } // Рестарт public void RestartGame() { Time.timeScale = 1f; SceneManager.LoadScene(SceneManager.GetActiveScene().name); } void UpdateUI() { scoreText.text = "Score: 0"; timeText.text = "Time: " + Mathf.Ceil(timeLeft); } }