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 List targets; public int score; public TextMeshProUGUI scoreText; public TextMeshProUGUI gameOverText; private float spawnRate = 1.0f; public Button restartButton; public bool isGameActive; public GameObject titleScreen; //for safe and load public int diff; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { } public void StartGame(int difficulty) { isGameActive = true; StartCoroutine(SpawnTarget()); score = 0; UpdateScore(0); titleScreen.gameObject.SetActive(false); spawnRate /= difficulty; diff = difficulty; } public void RestartGame() { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } public void GameOver() { gameOverText.gameObject.SetActive(true); restartButton.gameObject.SetActive(true); isGameActive = false; } IEnumerator SpawnTarget() { while (isGameActive) { yield return new WaitForSeconds(spawnRate); int index = Random.Range(0, targets.Count); Instantiate(targets[index]); } } public void UpdateScore(int scoreToAdd) { score += scoreToAdd; scoreText.text = "Score: " + score; } public void SaveGame() { SaveSystem.SaveGame(this); } public void LoadGame() { GameData data = SaveSystem.LoadGame(); score = data.score; scoreText.text = "Score: " + score; diff=data.difficulty; } // Update is called once per frame void Update() { if(Input.GetKeyDown(KeyCode.Q)) { SaveGame(); } if(Input.GetKeyDown(KeyCode.E)) { LoadGame(); } } }