Brackeys Quiz Game into Multiple Choice

Hello, I’m trying to make a quiz game with a tutorial made by Brackeys (https://www.youtube.com/playlist?list=PLPV2KyIb3jR7ucA2yo5pjvKY0cJmNTq2L) but I don’t know how to turn the true and false format into a multiple choice one with 4 different answers. I’m still unfamiliar to C# and I hope I can get help.

Here’s my code:
Game Master:

using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class GameMaster : MonoBehaviour {

    public Question[] questions;
    private static List<Question> unansweredQuestions;

    private Question currentQuestion;

    [SerializeField]
    private Text questionText;

    [SerializeField]
    private Text answer1;

    [SerializeField]
    private Text answer2;

    [SerializeField]
    private Text answer3;

    [SerializeField]
    private Text answer4;


    void Start()
    {
        if (unansweredQuestions == null || unansweredQuestions.Count == 0)
        {
            unansweredQuestions = questions.ToList<Question>();
        }

        SetCurrentQuestion ();
    }

    void SetCurrentQuestion ()
    {
        int randomQuestionIndex = Random.Range (0, unansweredQuestions.Count);
        currentQuestion = unansweredQuestions [randomQuestionIndex];

        questionText.text = currentQuestion.question;
        answer1.text = currentQuestion.answer1;
        answer2.text = currentQuestion.answer2;
        answer3.text = currentQuestion.answer3;
        answer4.text = currentQuestion.answer4;

        unansweredQuestions.RemoveAt(randomQuestionIndex);
    }
    public void UserSelect ()
    {
        if (currentQuestion.rightAnswer) {
            Debug.Log ("Correct!");
        } else
        {
            Debug.Log ("Wrong!");
        }
    }
       
}

Questions:

[System.Serializable]
public class Question {
    public string question;
    public string answer1 = "";
    public string answer2 = "";
    public string answer3 = "";
    public string answer4 = "";
    public int rightAnswer = 1;
}

Thanks.

1 Like

You could either make your answers classes (each contain an int or bool for ‘right answer’) and add the (4) answers to your question class… or you could use an array for your answers and ‘right answer’ could be the index which is correct.
A couple of options to consider :slight_smile:

1 Like

This should get you on the right direction.