using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using TMPro; using UnityEditor.Overlays; using UnityEngine.UI; using UnityEngine; public class GameManager : MonoBehaviour { public TextMeshProUGUI timeRemainingText; public TextMeshProUGUI orbsCollectedText; public bool isGameActive; public GameObject GameOverScreen; public GameObject VictoryScreen; public float playerPosX; public float playerPosY; public float playerPosZ; public float playerRotX; public float playerRotY; public float playerRotZ; public int orbsCollected = 0; public float seed; public List orbs; public float timeRemaining = 100; public int settings; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { isGameActive = true; for (int i = 0; i < orbs.Count; i++) { Instantiate(orbs[i], new Vector3(10*i, 5, 10*i), Quaternion.identity); } } public void RestartGame() { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } public void GameOver() { GameOverScreen.SetActive(true); isGameActive = false; } public void Victory() { VictoryScreen.SetActive(true); isGameActive = false; } public void SaveGame() { SaveSystem.SaveGame(this); } public void LoadGame() { GameData data = SaveSystem.LoadGame(); playerPosX = data.playerPosX; playerPosY = data.playerPosY; playerPosZ = data.playerPosZ; playerRotX = data.playerRotX; playerRotY = data.playerRotY; playerRotZ = data.playerRotZ; orbsCollected = data.orbsCollected; seed = data.seed; for (int i = 0; i < orbs.Count; i++) { } isGameActive = data.isGameActive; timeRemaining = data.timeRemaining; settings = data.settings; } // Update is called once per frame void Update() { UpdateTimeRemaining(); //Victory if (orbsCollected == 20) { Victory(); } //Game Over if (timeRemaining == 0) { GameOver(); } if(Input.GetKeyDown(KeyCode.F5)) { SaveGame(); } if(Input.GetKeyDown(KeyCode.F9)) { LoadGame(); } } public void UpdateTimeRemaining() { timeRemaining -= Time.deltaTime; timeRemainingText.text = "RemainingTime: " + timeRemaining * Time.deltaTime; } public void UpdateCollectedOrbs() { orbsCollected++; orbsCollectedText.text = "Collected Orbs: " + orbsCollected; } }