Beispiel #1
0
    private void OnEnable()
    {
        if (!isInitialized)
        {
            Initialize();
        }
        //initialise question
        checkedAnswer            = IsAnswerCorrect.unanswered;
        QuestionPanelGroup.alpha = 1;
        ActiveQuestion           = QuestionQueue.Dequeue();
        QuestionQueue.Enqueue(ActiveQuestion);
        txtQuestion.text = ActiveQuestion.Question;

        foreach (var button in ButtonList)
        {
            button.image.color = Color.gray;
        }

        random = new System.Random();//using system.Random to differentiate from UnityEngine.Random

        //Assign quesion answers to list
        Answers.Clear();//clear previous answers
        Answers.Add(ActiveQuestion.Answer);
        Answers.Add(ActiveQuestion.FakeAnswerOne);
        Answers.Add(ActiveQuestion.FakeAnswerTwo);
        Answers.Add(ActiveQuestion.FakeAnswerThree);
        //shuffle list
        Shuffle(Answers);

        //Assign text to box and button text
        AnswerList[0].GetComponentInChildren <Text>().text = Answers[0];
        AnswerList[1].GetComponentInChildren <Text>().text = Answers[1];
        AnswerList[2].GetComponentInChildren <Text>().text = Answers[2];
        AnswerList[3].GetComponentInChildren <Text>().text = Answers[3];
    }
Beispiel #2
0
    void CheckAnswer(string contentString)
    {
        //checks if answer given is correct
        if (contentString == ActiveQuestion.Answer)
        {
            checkedAnswer = IsAnswerCorrect.yes;
        }
        else
        {
            checkedAnswer = IsAnswerCorrect.no;
        }

        btnClickedButton = EventSystem.current.currentSelectedGameObject.gameObject.GetComponent <Button>();
    }
Beispiel #3
0
    void Initialize()
    {
        isInitialized  = true;
        ActiveQuestion = null;
        QuestionQueue  = new Queue <TriviaQuestion>();
        Questions      = new List <TriviaQuestion>();
        Answers        = new List <string>();
        checkedAnswer  = IsAnswerCorrect.unanswered;
        isAnswered     = false;
        //Get Question object from API
        Questions  = ApiHelper.GetQuestions();
        closeTimer = 0f;

        //initialise queue for each question from API
        foreach (TriviaQuestion question in Questions)
        {
            QuestionQueue.Enqueue(question);
        }
    }