private void checkAnswer() { if (!questionLoaded || _answers.Count == 0) { return; } bool correct = true; int wrongId = 0; for (int i = 0; i < _answers.Count; ++i) { if (_answers[i].GetComponentInChildren <Toggle>().isOn != _activeQuestion.answers[i].correct) { correct = false; wrongId = i; break; } } if (!correct && _playerData.health > 0) { if (lastHint != null) { Destroy(lastHint, 0f); lastHint = null; } lastHint = displayParagraph(questionUI, _activeQuestion.answers[wrongId].hint, 0, lastUIBottom - answerSpacing); _playerData.health--; healthObject.transform.GetChild(_playerData.health).GetComponent <Image>().enabled = false; audioData.Play(); for (var i = 0; i < _answers.Count; ++i) { _answers[i].GetComponentInChildren <Toggle>().isOn = false; } } else if (correct) { if (lastHint != null) { Destroy(lastHint, 0f); lastHint = null; } ans_handler.executeAnswer(questionLoadedID); lastHint = displayParagraph(questionUI, _activeQuestion.correctText, 0, lastUIBottom - answerSpacing); if (_activeQuestion.autoLoad && questionLoadedID < _questions.Count - 1) { eventDisplayQuestion(questionLoadedID + 1); } hideQuestion(_activeQuestion.readDelay); } }
void Start() { //Making an instance of the QuestionsHandler and loading the questions handler = gameObject.AddComponent <QuestionsHandler>(); ans_handler = GetComponent <AnswerHandler>(); handler.loadQuestions(); _questions = handler.GetQuestions().questions; _inventory = FindObjectOfType <InventoryManager>(); player = GameObject.Find("Player"); audioData = GetComponent <AudioSource>(); UnityEngine.EventSystems.EventSystem.current.sendNavigationEvents = !UnityEngine.EventSystems.EventSystem.current.sendNavigationEvents; for (int i = 0; i < progress; ++i) { ans_handler.executeAnswer(i); } }