I’m creating quiz game, where questions are randomized, but I don’t know how to do it.
I decided to randomize numbers and use these numbers as index of questions, but it won’t work for me.
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class Randomization : MonoBehaviour
{
public Text texxt; // this text is needed to display the question
public List<string> questions = new List<string>();
public List<int> previousQuestion = new List<int>();
public int questionNumber = 0;
public static int randQuestion = -1;
int Lenght = 6;
public List<int> list = new List<int>();
public void GenerateRandom()
{
for (int j = 0; j < Lenght; j++)
{
int Rand = Random.Range(0, 6);
while (list.Contains(Rand))
{
Rand = Random.Range(0, 6);
}
list.Add(Rand);
//Debug.Log(questions[list[j]]);
print(list[j]);
}
}
void Start()
{
GenerateRandom();
// texxt.text = questions[randQuestion].ToString();
}
void Update()
{
//previousQuestion[questionNumber] = randQuestion;
//questionNumber++;
//if (randQuestion == -1)
//{
// randQuestion = Random.Range(0, questions.Count);
// for (int i = 0; i < 6; i++)
// {
// if (randQuestion != previousQuestion[i])
// {
// }
// else
// {
// randQuestion = -1;
// }
// }
//}
//if (randQuestion > -1)
//{
// // texxt.text = questions[randQuestion].ToString();
// Debug.Log(questions[randQuestion]);
// previousQuestion[questionNumber] = randQuestion;
// questionNumber++;
//}
}
//public void RandomCall()
//{
// //for(int i = 0; i < list.Count; i++)
// //{
// // Debug.Log(list[0]);//.ToString();
// texxt.text=questions[0];
// StartCoroutine("Hije");
// //}
//}
// IEnumerator Hije() //here I try to remove questions, it works nicely
//{
// yield return new WaitForSeconds(1);
// list.RemoveAt(0);
// questions.RemoveAt(0);
//}
}
Can someone help me, please?