GameManager.cs 876 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using TMPro;
  2. using UnityEngine;
  3. public class GameManager : MonoBehaviour
  4. {
  5. public static GameManager gameManager;
  6. public TextMeshProUGUI scoreText, timerText;
  7. public AudioSource gameWon;
  8. public float timeLeft = 120f;
  9. public bool gameRunning = true;
  10. private int currentScore = 0;
  11. void Awake()
  12. {
  13. gameManager = this;
  14. }
  15. void Update()
  16. {
  17. if (timeLeft > 0)
  18. {
  19. timeLeft -= Time.deltaTime;
  20. timerText.text = "Time: " + Mathf.Round(timeLeft) + "s";
  21. if (timeLeft <= 0) gameWon.Play();
  22. }
  23. else
  24. {
  25. gameRunning = false;
  26. timerText.text = "";
  27. scoreText.text = "Total Score: " + currentScore;
  28. }
  29. }
  30. public void AddPoints()
  31. {
  32. currentScore += 10;
  33. scoreText.text = "Score: " + currentScore;
  34. }
  35. }