How do I get random answers?


I am a newbie :stuck_out_tongue:
I like to have random answers.
So to make it harder for the player so if the question comes he can’t remember if it was the first one or the third.

private void ShowQuestion()

        // Get random question from the list.
        QuestionData questionData = questionPool[Random.Range(0, questionPool.Count)];
        // Remove it from the list, so we can't get it again.

        questionDisplayText.text = questionData.questionText;

        for (int i = 0; i < questionData.answers.Length; i++)
            GameObject answerButtonGameObject = answerButtonObjectPool.GetObject();

            AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton>();

timeRemaining = currentRoundData.timeLimitInSeconds;

If you use UI buttons in a Vertical Layout Group, you can simply change the sibling order or set it as first sibling with some random value.

like :

private void RandomiseButtons (List<Button> buttons)
    foreach (Button button in buttons)
        button.transform.SetSiblingIndex (Random.Range (0, buttons.Count));

You could shuffle your list of answers before you create the buttons.