How do I get random answers?

Hello,

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()
    {
        RemoveAnswerButtons();

        // 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.
        questionPool.Remove(questionData);

        questionDisplayText.text = questionData.questionText;


        for (int i = 0; i < questionData.answers.Length; i++)
        {           
            GameObject answerButtonGameObject = answerButtonObjectPool.GetObject();
            answerButtonGameObjects.Add(answerButtonGameObject);
            answerButtonGameObject.transform.SetParent(answerButtonParent);

            AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton>();
            answerButton.Setup(questionData.answers*);*

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.

http://stackoverflow.com/questions/273313/randomize-a-listt