GameManager.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using TMPro;
  2. using UnityEditor.SearchService;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. public class GameManager : MonoBehaviour
  6. {
  7. public enum GameState
  8. {
  9. Paused,
  10. Playing,
  11. GameOver,
  12. Won
  13. }
  14. public static GameManager gameManagerInstance { get; private set; }
  15. [SerializeField] int currentOrbCounter = 0;
  16. [SerializeField] int maximumOrbs = 10;
  17. [SerializeField] TextMeshProUGUI orbCounterText;
  18. public GameState gameState = GameState.Playing;
  19. private void Awake()
  20. {
  21. if(gameManagerInstance == null)
  22. {
  23. gameManagerInstance = this;
  24. DontDestroyOnLoad(gameObject);
  25. }
  26. else
  27. {
  28. Destroy(gameObject);
  29. return;
  30. }
  31. }
  32. private void Update()
  33. {
  34. if(gameState == GameState.GameOver)
  35. {
  36. SceneManager.LoadScene("GameOverScene");
  37. }
  38. }
  39. public void IncreaseOrbCounter()
  40. {
  41. currentOrbCounter++;
  42. orbCounterText.text = currentOrbCounter.ToString();
  43. checkAllOrbsCollected(currentOrbCounter);
  44. }
  45. private void checkAllOrbsCollected(int currentOrbCounter)
  46. {
  47. if(currentOrbCounter == maximumOrbs)
  48. {
  49. gameState = GameState.Won;
  50. Debug.Log("Player won! All orbs were collected!");
  51. SceneManager.LoadScene("VictoryScene");
  52. }
  53. }
  54. }