Once they have answered correctly, another questions would come up, e.g. 7 circles, with a range of incorrect answers.
The parts that I see are:
The question has the name of the shape in it
The number of shapes can be random within a range
The shape itself can be random (square, triangle, circle etc.)
The answers can be random within a range, although one of them must be correct
The position of the correct answer must be random each time
The number of available answers can be different (usually 3,4,5)
I am not sure what is the best approach to build something like this? Is it best to pre-define the questions in some sort of array? Or, should each question be built as a scene with scenes randomly called? Or can it be truly random and built on the fly?
Any advice you can give would be greatly appreciated.
Thank you so much for your answer. I really like the idea of having it random as well. I have watched a few quiz tutorials online and they all seem to favour the array approach, which I feel may be a little limiting.
I am ok with instantiating objects, but how can I get them positioned correctly on the screen? For example, if I had 10 squares, I may want them to be displayed as 2 rows of 5? Normally when I have instantiated objects, they are either in one place or completely random. These would need to be ordered?
Also, is there a way to shuffle a list of answers to randomise which button gets the answer?
you could put empty placeholders (probably using UI elements, to work with different screensizes)
on those valid positions, and then instantiate objects on their positions (or as a child), if you want them evenly
on 2 rows, can instantiate half on top row placeholders and so on.
actually if you only have few different shapes,
i’d just put them there already and activate/deactivate when needed. (saves you from having to instantiate)
or, have empty UI image there, then assign the selected shape image to them.
That is interesting, I was thinking about that but there are quite a lot of variations or numbers and shapes.
I have started to write the script to display random shapes in a grid, but when I load, it comes up with the lower number of shapes at the top and the higher number at the bottom.
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HowMany3 : MonoBehaviour
{
[SerializeField]
private GameObject[] prefabs;
private int randomPrefab;
[SerializeField]
private int numPrefabs;
public int columnLength, rowLength;
public float xSpace, ySpace;
private void Start()
{
numPrefabs = Random.Range(1, 6);
randomPrefab = Random.Range(0, 3);
for(int i = 0; i < numPrefabs; i++)
{
Instantiate(prefabs[randomPrefab], new Vector2(xSpace * (i % columnLength), ySpace * (i / columnLength)), Quaternion.identity);
}
}
}
I belive this is because y grows upwards and your instantiation starts from the bottom of the screen. The easiest way to solve this is probably to set the max y and start decreasing the y value from there.
Create [SerializeField] private float maxY (or name it shapesInstantiateVerticalStartingPoint etc for better understanding of your script in the future). In Unity inspector give it a value, for example 7. Change your instantiate vector2 y value like this: maxY -ySpace * (i / columnLength) and try it out.