- Home /
how to randomize questions but still show all the questions?
I managed to randomize my questions. But the problem is, when the last question pops up first, the game seems to end already. Not displaying my other questions.
Comment
Answer by ShadyProductions · Jul 23, 2017 at 04:47 AM
I assume you grab a random from a list.
When you take the random question, you should remove it from the list.
Then as your end game condition check if the list is empty.
And not have your condition be the last question in the list.
Example:
You will need these references:
using System.Collections.Generic;
using System.Linq;
Script:
private System.Random _random = new System.Random();
public List<int> questionIds = new List<int> { 1, 2, 3, 4, 5 };
public int TakeRandom()
{
var value = questionIds[_random.Next(questionIds.Count)];
questionIds.Remove(value);
return value;
}
public void EndGame()
{
if (!questionIds.Any())
{
// End game
}
}
Your answer
Follow this Question
Related Questions
How to check the result after playing in quiz game?[Solve] -1 Answers
Randomizing numbers on a list. 4 Answers
random array instance 2 Answers
Making a randomizer script for a basic "Runner" game... 1 Answer
Quiz game with images 0 Answers