Answer the question
In order to leave comments, you need to log in
Why does random have the same value?
I'm making a quiz game where you answer questions, after you've answered the next question, and so on.
I need the questions to be in random order and without repetition, for this I have a variable of type string.
I found one video where everything worked out for a person, but now it randomizes at the beginning, and then I get the same question.
Here is the video
And the code I copied
public Text texxt;
public List<string> questions = new List<string>();
public List<int> previousQuestion = new List<int>();
public int questionNumber = 0;
public static string selectedAnswer;
public static int randQuestion = -1;
void Start()
{
texxt = GetComponent<Text>();
}
void Update()
{
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++;
}
}
Answer the question
In order to leave comments, you need to log in
on the Internet, very little is written about the random string type in unity
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question