| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using TMPro;
- using UnityEditor.SearchService;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour
- {
- public enum GameState
- {
- 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.Playing;
-
- private void Awake()
- {
- if(gameManagerInstance == null)
- {
- gameManagerInstance = this;
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- return;
- }
- }
- private void Update()
- {
- if(gameState == GameState.GameOver)
- {
- SceneManager.LoadScene("GameOverScene");
- }
- }
- public void IncreaseOrbCounter()
- {
- currentOrbCounter++;
- orbCounterText.text = currentOrbCounter.ToString();
- checkAllOrbsCollected(currentOrbCounter);
- }
- private void checkAllOrbsCollected(int currentOrbCounter)
- {
- if(currentOrbCounter == maximumOrbs)
- {
- gameState = GameState.Won;
- Debug.Log("Player won! All orbs were collected!");
- SceneManager.LoadScene("VictoryScene");
- }
- }
- }
|