ZoeAppClass/Assets/Jogos/268/Scripts/A3FT_QuestionManager.cs

66 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class A3FT_QuestionManager : MonoBehaviour
{
public List<A3FT_Dropper> questions;
private Animator canvasAnim;
private List<int> possibleAnswers = new List<int>();
private int questionsAnswered;
private Transform answerContainer;
private void Awake()
{
canvasAnim = GameObject.Find("A3FTCanvas").GetComponent<Animator>();
List<A3FT_Dropper> tempList = new List<A3FT_Dropper>();
answerContainer = GameObject.Find("AnswerPanel").transform;
tempList.AddRange(GameObject.Find("FamilyTree").GetComponentsInChildren<A3FT_Dropper>());
for(int i = 0; i < tempList.Count;i++)
{
possibleAnswers.Add(i);
}
GameControl jooj = GameObject.Find("GameControl").GetComponent<GameControl>();
jooj.finishedGame = false;
jooj.ended = false;
questions.AddRange(tempList);
PrepareAnswers();
}
public void PrepareAnswers()
{
for(int i = 0; i < questions.Count; i++)
{
int pickedNumber = Random.Range(0, possibleAnswers.Count);
int result = possibleAnswers[pickedNumber];
answerContainer.GetComponentsInChildren<A3FT_Dragger>()[i].SetupThis(result, questions[result].thisQuestion.thisAnswer);
questions[result].index = result;
possibleAnswers.RemoveAt(pickedNumber);
}
}
public void AddToAnswered()
{
questionsAnswered++;
if (questionsAnswered == questions.Count)
{
GameControl jooj = GameObject.Find("GameControl").GetComponent<GameControl>();
jooj.finishedGame = true;
//StartCoroutine(WonGame());
}
}
public IEnumerator WonGame()
{
canvasAnim.SetTrigger("Won");
yield return new WaitForSecondsRealtime(4);
GameControl jooj = GameObject.Find("GameControl").GetComponent<GameControl>();
jooj.finishedGame = true;
jooj.ended = true;
}
}