GameManager.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine.SceneManagement;
  4. using TMPro;
  5. using UnityEditor.Overlays;
  6. using UnityEngine.UI;
  7. using UnityEngine;
  8. public class GameManager : MonoBehaviour
  9. {
  10. public TextMeshProUGUI timeRemainingText;
  11. public TextMeshProUGUI orbsCollectedText;
  12. public bool isGameActive;
  13. public GameObject GameOverScreen;
  14. public GameObject VictoryScreen;
  15. public float playerPosX;
  16. public float playerPosY;
  17. public float playerPosZ;
  18. public float playerRotX;
  19. public float playerRotY;
  20. public float playerRotZ;
  21. public int orbsCollected = 0;
  22. public float seed;
  23. public List<GameObject> orbs;
  24. public int timeRemaining = 20;
  25. public int settings;
  26. // Start is called once before the first execution of Update after the MonoBehaviour is created
  27. void Start()
  28. {
  29. }
  30. public void StartGame(int difficulty)
  31. {
  32. isGameActive = true;
  33. }
  34. public void RestartGame()
  35. {
  36. SceneManager.LoadScene(SceneManager.GetActiveScene().name);
  37. }
  38. public void GameOver()
  39. {
  40. GameOverScreen.SetActive(true);
  41. isGameActive = false;
  42. }
  43. public void Victory()
  44. {
  45. VictoryScreen.SetActive(true);
  46. isGameActive = false;
  47. }
  48. public void SaveGame()
  49. {
  50. SaveSystem.SaveGame(this);
  51. }
  52. public void LoadGame()
  53. {
  54. GameData data = SaveSystem.LoadGame();
  55. playerPosX = data.playerPosX;
  56. playerPosY = data.playerPosY;
  57. playerPosZ = data.playerPosZ;
  58. playerRotX = data.playerRotX;
  59. playerRotY = data.playerRotY;
  60. playerRotZ = data.playerRotZ;
  61. orbsCollected = data.orbsCollected;
  62. seed = data.seed;
  63. for (int i = 0; i < orbs.Count; i++)
  64. {
  65. }
  66. isGameActive = data.isGameActive;
  67. timeRemaining = data.timeRemaining;
  68. settings = data.settings;
  69. }
  70. // Update is called once per frame
  71. void Update()
  72. {
  73. UpdateTimeRemaining();
  74. //Victory
  75. if (orbsCollected == orbs.Count)
  76. {
  77. Victory();
  78. }
  79. //Game Over
  80. if (timeRemaining == 0)
  81. {
  82. GameOver();
  83. }
  84. if(Input.GetKeyDown(KeyCode.F5))
  85. {
  86. SaveGame();
  87. }
  88. if(Input.GetKeyDown(KeyCode.F9))
  89. {
  90. LoadGame();
  91. }
  92. }
  93. public void UpdateTimeRemaining()
  94. {
  95. timeRemaining--;
  96. timeRemainingText.text = "RemainingTime: " + timeRemaining * Time.deltaTime;
  97. }
  98. public void UpdateCollectedOrbs()
  99. {
  100. orbsCollected++;
  101. orbsCollectedText.text = "Collected Orbs: " + orbsCollected;
  102. }
  103. }