I am making a quiz game in Unity 2d and it’s almost complete (excluding all the questions, but that’s not important). All my questions and answers are in a List, they are in “questions” List and “correctAnswer” List. The questions are randomized and i want to make it that if a question is picked by random at least once, then it won’t be used again, meaning it won’t be used by the randomizer.
Sorry if i used something incorrectly, i’m a beginner.
What is in questions is not important it’s in another language.
P.S. I am looking for how to make random range not to repeat.
List<string> questions = new List<string>() { "Pasaules augstākais kalns?", "Kas ir Vācijas galvaspilsēta?", "Kur atrodas ASV?", "Geo jautājums 4", "jt", "Geo jautājums 5", "Cik ir 2+2?", "Cik ir 12+1?", "Cik ir 9+10?", "Kvadrātsakne no 49", "2+2=5?" };
List<string> correctAnswer = new List<string>() { "3", "1", "2", "3", "1", "2", "2", "3", "1", "1" };
public static string selectedAnswer;
public Transform resultObj;
public static string choiceSelected = "n";
public static int randQuestion = -1;
public int catMod = 0;
public Transform auraObj;
public float totalCorrect = 0;
public float totalQuestions = 0;
public Transform scoreObj;
public float scorePer;
public Transform nextButton;
public Transform firstText;
public Transform secondText;
public Transform thirdText;
public Transform firstChild;
public Transform secondChild;
public Transform thirdChild;
void Start()
{
if (selectCat.catTopic == "Matemātika")
{
catMod = 5;
}
if (selectCat.catTopic == "Ģeogrāfija")
{
catMod = 0;
}
}
void FixedUpdate()
{
//scoreObj.GetComponent<TextMesh>().text = "Score : " +totalCorrect; nextButton.GetComponent<Transform>().position = new Vector3(28.8f, 8.62f, 0);
if (totalQuestions > 0)
{
scorePer = (totalCorrect / totalQuestions) * 100;
}
scoreObj.GetComponent<TextMesh>().text = "Score : " + scorePer+ "%";
if (randQuestion == -1)
{
randQuestion = Random.Range(0 + catMod, 5 + catMod);
nextButton.GetComponent<Transform>().position = new Vector3(49.1f, 8.62f, 0);
firstText.GetComponent<BoxCollider2D>().offset = new Vector2(-0.1f, 0.2f);
secondText.GetComponent<BoxCollider2D>().offset = new Vector2(-0.1f, 0.2f);
thirdText.GetComponent<BoxCollider2D>().offset = new Vector2(-0.1f, 0.2f);
firstChild.GetComponent<BoxCollider2D>().offset = new Vector2(0.05347621f, -5.174473f);
secondChild.GetComponent<BoxCollider2D>().offset = new Vector2(0.05347621f, -5.174473f);
thirdChild.GetComponent<BoxCollider2D>().offset = new Vector2(0.05347621f, -5.174473f);
}
if (randQuestion > -1)
{
GetComponent<TextMesh>().text = questions[randQuestion];
}
//Debug.Log(questions[randQuestion]);
if (choiceSelected == "y")
{
choiceSelected = "n";
totalQuestions += 1;
if (correctAnswer[randQuestion] == selectedAnswer)
{
resultObj.GetComponent<TextMesh>().text = "Pareizi! Ejiet pa labi lai turpinātu";
totalCorrect += 1;
nextButton.GetComponent<Transform>().position = new Vector3(28.8f, 8.62f, 0);
firstText.GetComponent<BoxCollider2D>().offset = new Vector2(50f, 0.2f);
secondText.GetComponent<BoxCollider2D>().offset = new Vector2(50f, 0.2f);
thirdText.GetComponent<BoxCollider2D>().offset = new Vector2(50f, 0.2f);
firstChild.GetComponent<BoxCollider2D>().offset = new Vector2(50f, -5.174473f);
secondChild.GetComponent<BoxCollider2D>().offset = new Vector2(50f, -5.174473f);
thirdChild.GetComponent<BoxCollider2D>().offset = new Vector2(50f, -5.174473f);
}
else
{
NextButton.resetAura = "n";
resultObj.GetComponent<TextMesh>().text = "Nepareizi!";
if (correctAnswer[randQuestion] == "1")
{
auraObj.GetComponent<Transform> ().position = new Vector3(-3.4f, 24.2f, 0);
}
if (correctAnswer[randQuestion] == "2")
{
auraObj.GetComponent<Transform>().position = new Vector3(9.9f, 24.2f, 0);
}
if (correctAnswer[randQuestion] == "3")
{
auraObj.GetComponent<Transform>().position = new Vector3(22.9f, 24.2f, 0);
}
nextButton.GetComponent<Transform>().position = new Vector3(28.8f, 8.62f, 0);
firstText.GetComponent<BoxCollider2D>().offset = new Vector2(50f, 0.2f);
secondText.GetComponent<BoxCollider2D>().offset = new Vector2(50f, 0.2f);
thirdText.GetComponent<BoxCollider2D>().offset = new Vector2(50f, 0.2f);
firstChild.GetComponent<BoxCollider2D>().offset = new Vector2(50f, -5.174473f);
secondChild.GetComponent<BoxCollider2D>().offset = new Vector2(50f, -5.174473f);
thirdChild.GetComponent<BoxCollider2D>().offset = new Vector2(50f, -5.174473f);
}
}
}
}