90 lines
2.4 KiB
C#
90 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class A13DQuestionManager : MonoBehaviour
|
|
{
|
|
public static A13DQuestionManager instance;
|
|
public List<A13DQuestionClass> questions = new List<A13DQuestionClass>();
|
|
public GameObject answerPrefab, questionPrefab;
|
|
public Transform answersOrganizer, questionsOrganizer;
|
|
private int currentIndex, correctAnswers;
|
|
private Animator anim;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
currentIndex = 0;
|
|
anim = GetComponent<Animator>();
|
|
SetupQuestion();
|
|
GameControl.instance.StartedGame();
|
|
}
|
|
|
|
public void SetupQuestion()
|
|
{
|
|
for (int i = 0; i < questions[currentIndex].answers.Count; i++)
|
|
{
|
|
A13DDropper tempD = Instantiate(questionPrefab, questionsOrganizer, false).GetComponent<A13DDropper>();
|
|
tempD.SetupThis(i);
|
|
}
|
|
SetupAnswer();
|
|
}
|
|
|
|
public void SetupAnswer()
|
|
{
|
|
for (int i = 0; i < questions[currentIndex].answers.Count; i++)
|
|
{
|
|
A13DDragger tempD = Instantiate(answerPrefab, answersOrganizer, false).GetComponent<A13DDragger>();
|
|
tempD.SetupThis(questions[currentIndex].answers[i]);
|
|
}
|
|
}
|
|
|
|
public void CorrectAnswer()
|
|
{
|
|
correctAnswers++;
|
|
A10D1AudioSystem.instance.Correct();
|
|
if (correctAnswers == questions[currentIndex].answers.Count)
|
|
{
|
|
anim.SetTrigger("Correct");
|
|
StartCoroutine(WaitForNext());
|
|
currentIndex++;
|
|
correctAnswers = 0;
|
|
}
|
|
|
|
}
|
|
|
|
public void WrongAnswer()
|
|
{
|
|
anim.SetTrigger("Wrong");
|
|
A10D1AudioSystem.instance.Wrong();
|
|
}
|
|
|
|
public void CleanOrganizers()
|
|
{
|
|
for (int i = 0; i < answersOrganizer.childCount; i++)
|
|
{
|
|
Destroy(answersOrganizer.GetComponentsInChildren<A13DDragger>()[i].gameObject);
|
|
}
|
|
for (int n = 0; n < questionsOrganizer.childCount; n++)
|
|
{
|
|
Destroy(questionsOrganizer.GetComponentsInChildren<A13DDropper>()[n].gameObject);
|
|
}
|
|
}
|
|
|
|
IEnumerator WaitForNext()
|
|
{
|
|
yield return new WaitForSeconds(2);
|
|
if (currentIndex < questions.Count)
|
|
{
|
|
CleanOrganizers();
|
|
SetupQuestion();
|
|
}
|
|
else
|
|
{
|
|
GameControl.instance.FinishGame();
|
|
}
|
|
|
|
}
|
|
}
|