2023-04-23 22:18:37 -07:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.SceneManagement;
|
2023-04-25 15:38:12 -07:00
|
|
|
using UnityEngine.UI;
|
2023-04-23 22:18:37 -07:00
|
|
|
|
|
|
|
public class SceneController : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
// this object will always exist!
|
|
|
|
void Awake() {
|
2023-04-25 15:38:12 -07:00
|
|
|
// check to see if a state controller already exists
|
|
|
|
if (GameObject.FindGameObjectWithTag("SceneManager") != null) {
|
|
|
|
Destroy(this.gameObject);
|
|
|
|
} else { // if it doesn't, then this is the only one
|
|
|
|
this.gameObject.tag = "SceneManager";
|
|
|
|
}
|
2023-04-23 22:18:37 -07:00
|
|
|
DontDestroyOnLoad(this.gameObject);
|
2023-04-25 15:38:12 -07:00
|
|
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
|
|
|
|
GameObject pauseMenu = GameObject.Find("PauseMenuCanvas");
|
|
|
|
if (pauseMenu != null) {
|
|
|
|
Button quitButton = GameObject.Find("QuitButton").GetComponent<Button>();
|
|
|
|
quitButton.onClick.AddListener(BackToMainMenu);
|
|
|
|
}
|
|
|
|
if (scene.buildIndex == 0) { // if this is the menu
|
|
|
|
GameObject.Find("NewGameButton").GetComponent<Button>().onClick.AddListener(NextScene);
|
|
|
|
}
|
2023-04-23 22:18:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void NextScene() {
|
|
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
|
|
|
}
|
|
|
|
|
2023-04-25 15:38:12 -07:00
|
|
|
public void BackToMainMenu() {
|
|
|
|
SceneManager.LoadScene(0); // main menu scene should be 0
|
|
|
|
}
|
|
|
|
|
2023-04-26 13:03:48 -07:00
|
|
|
public void LoadChosenScene(int index) {
|
|
|
|
SceneManager.LoadScene(index);
|
|
|
|
}
|
|
|
|
|
2023-04-23 22:18:37 -07:00
|
|
|
}
|