karen_constantine

Untitled

Apr 9th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using UnityEngine.UI;
  4.  
  5. public class GameController : MonoBehaviour
  6. {
  7. public static GameController instance;
  8.  
  9. public GameObject gameOverText;
  10. public Text scoreText;
  11.  
  12. private int score = 0;
  13. private bool gameOver = false;
  14.  
  15. void Awake()
  16. {
  17. if (instance == null)
  18. {
  19. instance = this;
  20. }
  21. else if (instance != this)
  22. {
  23. Destroy(gameObject);
  24. }
  25. }
  26.  
  27. void Update()
  28. {
  29. if (gameOver && Input.GetMouseButtonDown(0))
  30. {
  31. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  32. }
  33. }
  34.  
  35. public void BirdScored()
  36. {
  37. if (gameOver)
  38. {
  39. return;
  40. }
  41.  
  42. score++;
  43. scoreText.text = "Score: " + score.ToString();
  44. }
  45.  
  46. public void BirdDied()
  47. {
  48. gameOverText.SetActive(true);
  49. gameOver = true;
  50. }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment