94 lines
2.5 KiB
C#
94 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class A11G6QuestionManager : MonoBehaviour
|
|
{
|
|
public static A11G6QuestionManager instance;
|
|
public A11G6Droper questionD;
|
|
public Text questionText;
|
|
public List<A11G6QuestionClass> questions = new List<A11G6QuestionClass>();
|
|
public Transform answerOrganizer;
|
|
private List<A11G6Dragger> answerDs = new List<A11G6Dragger>();
|
|
private Coroutine running = null;
|
|
private Animator anim;
|
|
private int currentIndex, nAnswers, nAnswered;
|
|
|
|
public void Awake()
|
|
{
|
|
anim = GetComponent<Animator>();
|
|
instance = this;
|
|
for (int i = 0; i < answerOrganizer.childCount;i++)
|
|
{
|
|
answerDs.Add(answerOrganizer.GetComponentsInChildren<A11G6Dragger>()[i]);
|
|
}
|
|
NextQuestion();
|
|
GameControl.instance.StartedGame();
|
|
}
|
|
|
|
public void CorrectAnswer()
|
|
{
|
|
anim.SetTrigger("Correct");
|
|
A10D1AudioSystem.instance.Correct();
|
|
nAnswered++;
|
|
Debug.Log("Correct answers : " + nAnswered + ". Answers Remaining : " + nAnswers);
|
|
if (nAnswered == nAnswers)
|
|
{
|
|
if (running == null)
|
|
{
|
|
running = StartCoroutine(WaitToNext());
|
|
}
|
|
else
|
|
{
|
|
StopCoroutine(running);
|
|
running = StartCoroutine(WaitToNext());
|
|
}
|
|
}
|
|
}
|
|
|
|
public void WrongAnswer()
|
|
{
|
|
anim.SetTrigger("Wrong");
|
|
A10D1AudioSystem.instance.Wrong();
|
|
}
|
|
|
|
public void SetupAnswers()
|
|
{
|
|
for (int i = 0; i < questions[currentIndex].answers.Count; i++)
|
|
{
|
|
answerDs[i].SetupThis(questions[currentIndex].answers[i]);
|
|
}
|
|
}
|
|
|
|
public void NextQuestion()
|
|
{
|
|
if (currentIndex < questions.Count)
|
|
{
|
|
nAnswers = 0;
|
|
nAnswered = 0;
|
|
for (int i = 0; i < questions[currentIndex].answers.Count; i++)
|
|
{
|
|
if (questions[currentIndex].answers[i].isCorrect)
|
|
{
|
|
nAnswers++;
|
|
}
|
|
}
|
|
questionD.SetupThis(questions[currentIndex]);
|
|
questionText.text = questions[currentIndex].questionTitle;
|
|
SetupAnswers();
|
|
}
|
|
else
|
|
{
|
|
GameControl.instance.FinishGame();
|
|
}
|
|
}
|
|
|
|
IEnumerator WaitToNext()
|
|
{
|
|
currentIndex++;
|
|
yield return new WaitForSecondsRealtime(3);
|
|
NextQuestion();
|
|
}
|
|
}
|