We provide a simple method named LoadQuestion to pull the values from our data classes into the UI and display them to the player. The code looks like this:
private void LoadQuestion(int index) { if (index < questions.Length) { questionText.text = questions[index].questionText; firstAnswerButton.GetComponentInChildren<Text>().text = questions[index].answers[0].answerText; secondAnswerButton.GetComponentInChildren<Text>().text = questions[index].answers[1].answerText; thirdAnswerButton.GetComponentInChildren<Text>().text = questions[index].answers[2].answerText; } else { EndConversation(); }}
The LoadQuestion method takes in a question index, which corresponds to the index of the question in the array questions[] ...