Am I missing something or is this correct for a game manager script or am I overcomplicating it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Cinemachine;
public class GameManager : MonoBehaviour
{
public static GameManager instance; // Singleton instance
public bool isGameStarted = false; // Flag for checking if game has started
public bool isGamePaused = false; // Flag for checking if game is paused
public string savedGameTimestamp; // Time stamp for saved game
public List cutSceneNames = new List(); // List of cut scene names
public CinemachineVirtualCamera cutSceneCamera; // Reference to the cut scene camera
private void Awake()
{
if (instance == null)
{
instance = this; // Set instance to this object
DontDestroyOnLoad(gameObject); // Don’t destroy this object when changing scenes
}
else
{
Destroy(gameObject); // Destroy any duplicate instances of this object
}
}
private void Start()
{
LoadGame(); // Load the saved game
}
private void Update()
{
if (!isGameStarted)
{
if (Input.GetKeyDown(KeyCode.Space))
{
StartGame(); // Start the game when space bar is pressed
}
}
if (Input.GetKeyDown(KeyCode.Escape))
{
QuitGame(); // Quit the game when escape key is pressed
}
}
public void StartGame()
{
isGameStarted = true; // Set game started flag to true
}
public void QuitGame()
{
Application.Quit(); // Quit the application
}
public void SaveGame()
{
savedGameTimestamp = System.DateTime.Now.ToString(“yyyy-MM-dd_HH-mm-ss”); // Set saved game time stamp to current date and time
}
public void LoadGame()
{
// Load saved game if there is one
if (!string.IsNullOrEmpty(savedGameTimestamp))
{
Debug.Log("Loading saved game from " + savedGameTimestamp);
}
}
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName); // Load the specified scene
}
public void PlayCutScene(string cutSceneName)
{
// Play the specified cut scene
if (cutSceneNames.Contains(cutSceneName))
{
cutSceneCamera.gameObject.SetActive(true); // Enable the cut scene camera
Debug.Log("Playing cut scene " + cutSceneName);
}
else
{
Debug.LogError(“Cut scene " + cutSceneName + " not found!”);
}
}
public void StopCutScene()
{
cutSceneCamera.gameObject.SetActive(false); // Disable the cut scene camera
}
}