How to change it to show different numbers of answers

I am using the Quiz Master to help me with my Scuba Refresher course. The online materials generally have 4 answers for the multiple choice questions, but some have 3 or only 2. So I have made some simple modifications to two of the scripts that allows for this.

I also had to make my buttons fit the entire width within the lines on the background, because some of the answers were trying to be multiple lines with the narrower button width. Since the buttons fill the area, if you have less of them they get taller, but it still looks pretty good.

In QuestionSO.cs I changed how answers was declared and added a public method:

[SerializeField]
string[] answers;	// Number of elements is set in Unity Editor when this is initialized

/***
*		GetNumberOfAnswers returns the number of answers in the answers array.  This is set in the Unity Edtior.
***/
public int GetNumberOfAnswers()
{
	return answers.Length;
}   // GetNumberOfAnswers()

Then you simply change for loop in DisplayQuestion() for Quix.cs to enable buttons in use and disable buttons that are not used:

	for (int i = 0; i < answerButtons.Length; i++)
	{	// Change the text for all the buttons
		TextMeshProUGUI buttonText;

		if (i < currentQuestion.GetNumberOfAnswers())
		{   // We have an answer to show for this button
			answerButtons[i].SetActive(true);
			buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();
			buttonText.text = currentQuestion.GetAnswer(i);
		}	// if
		else
		{	// There is no answer for this button, so disable it to prevent it from showing or being clickable
			answerButtons[i].SetActive(false);
		}   // else
	}   // for

I think this makes it a bit more flexible in allowing for varied numbers of answers to different questions. This will be a great way for me to create something like a Flash Card quiz configuration.

The PADI material is broken into sections, so an additional enhancement might be to have a way to group different sets of questions and allow you to either repeat the section just completed or go on to the next section. I think that could be done by creating a SectionSO.cs, like QuestionSO.cs, for each section that would be used for the End Screen Canvas. I am just not sure how you could use LoadScene for that to tell it how to reload a specific section. Might require a Soliton class to tell it which section to start with and you have a list of SectionSO objects which each has a list of QuestionSO objects.

Would be interested in feedback on that idea.

1 Like

Phenomenal job! :fire:

@Brian_Trotter

Stay tuned. I have an updated version that added Sections to the Quiz that I am working on now. I think I can do it without using SceneManager to restart it as well.

I have this working now, but was wondering if there was a good way to make it available other than just pasting the source modules in a message. It no longer uses LoadScene() to start a new set of questions. The only new thing added was a new scriptable object called SectionSO.cs which contains the list of questions for that section.

I have finished the updates and it now has all the questions in it for the PADI Scuba Refresher course. There are a few multiple choice questions that are not supported with this version, but they were few and all the single answer ones are in here (I haven’t tested all of them, so some changes to the text may be needed to make them fit or the font size needs to be reduced further). An additional idea was to add a second slider that shows how far you are through all the sections.

Here is the URL to my GitHub repository for it: https://github.com/lvskiprof/Quiz-Master

Note that I am using 2021.03.0f1 version of Unity, so best to use that or a later version to load it.

Privacy & Terms