using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UIManager : MonoBehaviour { [SerializeField] private Text _scoreText; [SerializeField] private Sprite[] _liveSprites; [SerializeField] private Image _livesImage; [SerializeField] private Text _gameOverText; [SerializeField] private Text _gameRestartText; [SerializeField] private GameManager _gameManager; // Start is called before the first frame update void Start() { _scoreText.text = "Score: " + 0; _gameOverText.gameObject.SetActive(false); _gameRestartText.gameObject.SetActive(false); if (_gameManager == null) { Debug.LogError("GameManager is NULL."); } } // Update is called once per frame void Update() { } public void UpdateScore(int score) { _scoreText.text = "Score: " + score; } public void UpdateLives(int currentLives) { _livesImage.sprite = _liveSprites[currentLives]; if (currentLives == 0) { showGameOverScreen(); } } private void showGameOverScreen() { _gameRestartText.gameObject.SetActive(true); StartCoroutine(flickerGameOverText()); _gameManager.GameOver(); } private IEnumerator flickerGameOverText() { while (true) { _gameOverText.gameObject.SetActive(true); yield return new WaitForSeconds(0.3f); _gameOverText.gameObject.SetActive(false); yield return new WaitForSeconds(0.3f); } } }