Question Action

In this tutorial we will learn how to create a Question Action
We will modify an already existing prefab named QuestionPrefabExample and create a new question action.

Question Prefab Constructor

In order to create a Question Action, the most important part is to set the Question Prefab Constructor correctly.

First and foremost, we will spawn our Question Prefab example. To do so, we will drag and drop it either on the hierarchy or in the scene. After spawning the prefab, click on it. In the inspector tab you will be able to see the Question Prefab Constructor.

../../../_images/QuestionPrefabConstructorInspector.PNG

In the above photo we can see an example of a ready-to-use Question Action. We can see that the script has a lot of fields. The main distinguish in the script is between the different option types. There are three option types:

  • Header Options

  • Question Options

  • Other Options

Now, we will break up and analyze its option:

  1. Header Options: This groups the functionalities of the header UI. It has 3 fields:

  • Allow Text Header: If true, spawns first the header UI and then the options.

  • Text Header Lifetime: For how many seconds the header UI will be visible.

  • Text Of Header: The text of the header UI

  1. Question Options: This groups the functionalities of the Options UI. It has 3 fields:

  • Max Questions: The total amount of questions.

  • Answers With Order: If true, then there will be a choice order.

  • Option List: List of the option. There you can set which option is the correct one, the order of it and the text of the option.

  1. Other Options This groups some functionalities of the UI. It has two fields:

  • Shuffle Options: Spawns the options randomly each time

  • Reveal Correct Answers: After answering the question, the system will reveal the correct answer.

So after learning the basic fields of the Question Prefab Constructor, it is time to change the fields of it and put our own question and options!
First, let’s say that we want to ask “What’s 1+1?” and have 4 Options, 2,-2,1 and 11. We will replace the Text of Header to “What’s 1+1?”
After that, we will go to the Option list, delete the previous ones and add 4 new Options. In each Option Text we put the numbers we said above with the correct one being the 2. You can see the gif below on how to set up all the above:
../../../_images/ShowcaseQuestionPrefabConstructor.gif

Now, we just save our new prefab and copy its’ path and paste it in our Question Action script.

Results

Below you can see our new prefab while playing.

../../../_images/PlaytimeQuestionAction.gif