Getting Questions and Answers from XML file and applying them to the UI

I made the layout of the game, but the coding is throwing me off. How do I make it so instead of making a new label for every question, make it so that the text of the Label changes? When the question changes the answer changes as well so that it isn’t True-True-True-True for the entire game.

Would it be possible if the questions were made in a XML file?

It doesn’t matter what source the data is coming from. Load it into Data objects you store in memory. Etc define a class for one question and then keep a list or dictionary of them.

public class Question
{    
    public string text;
    public string[] answers = new string[4];
    public int answerId;
}

Keep a list of your questions and the current question

List<Question> questions = new List<Question>();
Question currentQuestion;

And create them somewhere as part of your loading

while (CanCreateQuestionFromXml())
    questions.Add(CreateNextQuestionFromXml());

And pick one at random etc…

currentQuestion = questions[Random.Range(0, questions.Count)];

And update your UI…

ui_question.text = currentQuestion.text;
ui_answer1.text = currentQuestion.answers[0];
ui_answer2.text = currentQuestion.answers[1];
ui_answer3.text = currentQuestion.answers[2];
ui_answer4.text = currentQuestion.answers[3];

And respond to button press etc…

public void OnAnswer1()
{
    correct = currentQuestion.answerId == 0;
    RefreshUI();
}
public void OnAnswer2()
{
    correct = currentQuestion.answerId == 1;
    RefreshUI();
}
public void OnAnswer3()
{
    correct = currentQuestion.answerId == 2;
    RefreshUI();
}

And so on…

https://welookups.com/xml/xml_syntax.html

welookups XML Tutorial
XML Syntax Rules
« Previous
Next Chapter »

The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.
XML Documents Must Have a Root Element

XML documents must contain one root element that is the parent of all other elements:

<subchild>.....</subchild>

,use this site
https://welookups.com/
HTML Tutorials
« HTML Home
Next Chapter HTML »

HTML

HTML is very important of web page you can create your web pages.

This tutorials teaches you everything about HTML and HTML5.

It’s is very simple