using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class MenuScript : MonoBehaviour { public Animator Black; private AudioManager Audio; private bool IsCoRunning; private void Awake() { DontDestroyOnLoad(this); } private void Start() { Black = GameObject.FindGameObjectWithTag("GameController").GetComponent<Animator>(); Audio = FindObjectOfType<AudioManager>(); } public void PlayGame() { Audio.PlayClip("Menu_Button_Click", 1, 1); if (!IsCoRunning) { StartCoroutine(LoadScene()); } } public void EndGame() { Audio.PlayClip("Menu_Button_Click", 1, 1); if (!IsCoRunning) { StartCoroutine(LoadMenu()); } } public void QuitGame() { Application.Quit(); } public IEnumerator LoadScene() { IsCoRunning = true; Black.SetBool("FadeOut", true); yield return new WaitForSeconds(1); SceneManager.LoadSceneAsync("MainScene"); yield return new WaitForSeconds(2); Black.SetBool("FadeIn", true); yield return new WaitForSeconds(1); Black.SetBool("FadeOut", false); Black.SetBool("FadeIn", false); IsCoRunning = false; } public IEnumerator LoadMenu() { IsCoRunning = true; Black.SetBool("FadeOut", true); yield return new WaitForSeconds(1); SceneManager.LoadSceneAsync("Menu"); Black.SetBool("FadeIn", true); yield return new WaitForSeconds(1); Cursor.visible = true; Black.SetBool("FadeOut", false); Black.SetBool("FadeIn", false); IsCoRunning = false; } }