Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class UIManager : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private Text _scoreText;
  10. [SerializeField]
  11. private Image _livesImage;
  12. private Player player;
  13. [SerializeField]
  14. private Sprite[] liveSprite;
  15. [SerializeField]
  16. private Text _gameOverText;
  17. [SerializeField]
  18. private Text _restartLevel;
  19. [SerializeField]
  20. private Text _goToMainMenu;
  21. private GameManager _gameManager;
  22. // Start is called before the first frame update
  23. void Start()
  24. {
  25. _scoreText.text = "Score: " + 0;
  26. _gameOverText.gameObject.SetActive(false);
  27. _gameManager = GameObject.Find("Game_Manager").GetComponent<GameManager>();
  28. if (_gameManager == null)
  29. {
  30. Debug.LogError("Game Manager is null");
  31. }
  32. }
  33.  
  34. public void UpdateScore(int playerScore)
  35. {
  36. _scoreText.text = "Score: " + playerScore;
  37. }
  38. public void UpdateLives(int currentLives)
  39. {
  40. _livesImage.sprite = liveSprite[currentLives];
  41. if (currentLives == 0)
  42. {
  43. GameOver();
  44. }
  45. void GameOver()
  46. {
  47. _gameManager.GameOver();
  48. StartCoroutine(GameOverFlicker());
  49. _gameOverText.gameObject.SetActive(true);
  50. _restartLevel.gameObject.SetActive(true);
  51. _goToMainMenu.gameObject.SetActive(true);
  52. }
  53. }
  54. IEnumerator GameOverFlicker()
  55. {
  56. while(true)
  57. {
  58. _gameOverText.text = "GAME OVER";
  59. yield return new WaitForSeconds(0.5f);
  60. _gameOverText.text = "";
  61. yield return new WaitForSeconds(0.5f);
  62.  
  63.  
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement