ZoeAppClass/Assets/Jogos/00 - Models/Maze/Scripts/Maze_Manager.cs

91 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Maze_Manager : MonoBehaviour
{
public static Maze_Manager instance;
public List<GameObject> levels = new List<GameObject>();
public List<string> questions = new List<string>();
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<Animator>();
currentLevel = GameObject.Find("Level").GetComponent<Maze_Level>();
player = GameObject.Find("Player").GetComponent<Maze_Player>();
titleTxt = GameObject.Find("TitleText").GetComponent<Text>();
feedbackTxt = GameObject.Find("FeedbackText").GetComponent<Text>();
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<Maze_Level>().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<Maze_Level>();
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");
}
}