using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Maze_Manager : MonoBehaviour { public static Maze_Manager instance; public List levels = new List(); public List questions = new List(); public int currentIndex = 0; public bool canPlay = false; private Text titleTxt,feedbackTxt; private Maze_Player player; private Maze_Level currentLevel; private Animator anim; public void Awake() { instance = this; anim = GetComponent(); currentLevel = GameObject.Find("Level").GetComponent(); player = GameObject.Find("Player").GetComponent(); titleTxt = GameObject.Find("TitleText").GetComponent(); feedbackTxt = GameObject.Find("FeedbackText").GetComponent(); anim.SetTrigger("DoPresentation"); StartCoroutine(FirstLevel()); GameControl.instance.StartedGame(); } public void ChangeQuestion() { currentIndex++; if (currentIndex < questions.Count) { anim.SetTrigger("DoPresentation"); feedbackTxt.text = "Correct! Next Question"; titleTxt.text = questions[currentIndex]; anim.SetTrigger("ShowFeedback"); anim.SetTrigger("ShowTitle"); StartCoroutine(WaitToSetCL()); } else { GameControl.instance.FinishGame(); } } public void StartStage() { currentLevel.GetComponent().StartLevel(); } public void Restart() { anim.SetTrigger("DoPresentation"); feedbackTxt.text = "Try again"; anim.SetTrigger("ShowFeedback"); StartCoroutine(WaitToRestart()); } IEnumerator WaitToRestart() { player.canMove = false; yield return new WaitForSeconds(3); currentLevel.RestartLevel(); anim.SetTrigger("ByePresentation"); } IEnumerator WaitToSetCL() { yield return new WaitForSeconds(1); Destroy(currentLevel.gameObject); yield return new WaitForEndOfFrame(); Maze_Level nextLevel = Instantiate(levels[currentIndex],Vector3.zero,Quaternion.Euler(0,0,0),transform).GetComponent(); nextLevel.gameObject.name = "Level"; yield return new WaitForSeconds(4); currentLevel = nextLevel; anim.SetTrigger("ByePresentation"); } IEnumerator FirstLevel() { yield return new WaitForSeconds(1); titleTxt.text = questions[currentIndex]; anim.SetTrigger("ShowTitle"); yield return new WaitForSeconds(4); anim.SetTrigger("ByePresentation"); } }