| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using TMPro;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour
- {
- public enum GameState
- {
- InMainMenu,
- Paused,
- Playing,
- GameOver,
- Won
- }
- public static GameManager gameManagerInstance { get; private set; }
- [SerializeField] int currentOrbCounter = 0;
- [SerializeField] int maximumOrbs = 10;
- [SerializeField] TextMeshProUGUI orbCounterText;
- public GameState gameState = GameState.InMainMenu;
- private void Awake()
- {
- if(gameManagerInstance == null)
- {
- gameManagerInstance = this;
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- return;
- }
- }
- private void Update()
- {
- switch (gameState)
- {
- case GameState.InMainMenu: break;
- case GameState.Playing:
- if(orbCounterText == null)
- {
- orbCounterText = GameObject.Find("Orb_Text").GetComponent<TextMeshProUGUI>();
- }
- break;
- case GameState.GameOver:
- SceneManager.LoadScene("GameOverScene");
- break;
- default:
- Debug.Log("GameState error");
- break;
- }
- }
- public void IncreaseOrbCounter()
- {
- currentOrbCounter++;
- string orbCounterString = currentOrbCounter.ToString() + " / " + maximumOrbs.ToString();
- orbCounterText.text = orbCounterString;
- checkAllOrbsCollected(currentOrbCounter);
- }
- private void checkAllOrbsCollected(int currentOrbCounter)
- {
- if(currentOrbCounter == maximumOrbs)
- {
- gameState = GameState.Won;
- Debug.Log("Player won! All orbs were collected!");
- SceneManager.LoadScene("VictoryScene");
- }
- }
- public void StartGame()
- {
- SceneManager.LoadScene("Sandbox");
- gameState = GameState.Playing;
- }
- }
|