Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class UIManager : MonoBehaviour
- {
- [SerializeField]
- private Text _scoreText;
- [SerializeField]
- private Image _livesImage;
- private Player player;
- [SerializeField]
- private Sprite[] liveSprite;
- [SerializeField]
- private Text _gameOverText;
- [SerializeField]
- private Text _restartLevel;
- [SerializeField]
- private Text _goToMainMenu;
- private GameManager _gameManager;
- // Start is called before the first frame update
- void Start()
- {
- _scoreText.text = "Score: " + 0;
- _gameOverText.gameObject.SetActive(false);
- _gameManager = GameObject.Find("Game_Manager").GetComponent<GameManager>();
- if (_gameManager == null)
- {
- Debug.LogError("Game Manager is null");
- }
- }
- public void UpdateScore(int playerScore)
- {
- _scoreText.text = "Score: " + playerScore;
- }
- public void UpdateLives(int currentLives)
- {
- _livesImage.sprite = liveSprite[currentLives];
- if (currentLives == 0)
- {
- GameOver();
- }
- void GameOver()
- {
- _gameManager.GameOver();
- StartCoroutine(GameOverFlicker());
- _gameOverText.gameObject.SetActive(true);
- _restartLevel.gameObject.SetActive(true);
- _goToMainMenu.gameObject.SetActive(true);
- }
- }
- IEnumerator GameOverFlicker()
- {
- while(true)
- {
- _gameOverText.text = "GAME OVER";
- yield return new WaitForSeconds(0.5f);
- _gameOverText.text = "";
- yield return new WaitForSeconds(0.5f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement