В следующем коде у меня есть массив для хранения вопросов.Я хочу, чтобы это выглядело случайным, когда игра начинается.Использование questionIndex = Random.Range(0, questionPool.Length);
удалось сделать, но дублирование все еще сохраняется и не останавливается в соответствии с индексом.
void Start()
{
audioPlayer = gameObject.AddComponent<AudioSource>();
dataController = FindObjectOfType<DataController>();
currentRoundData = dataController.GetCurrentRoundData();
questionPool = currentRoundData.questions;
timeRemaining = currentRoundData.timeLimitInSeconds;
UpdateTimeRemainingDisplay();
Time.timeScale = 1f;
playerScore = 0;
questionIndex = 0;
ShowQuestion();
isRoundActive = true;
}
void ShowQuestion()
{
RemoveAnswerButtons();
questionIndex = Random.Range(0, questionPool.Length);
QuestionData questionData = questionPool[questionIndex];
questionText.text = questionData.questionText;
for (int i = 0; i < questionData.answers.Length; i++)
{
GameObject answerButtonGameObject = answerButtonObjectPool.GetObject();
answerButtonGameObjects.Add(answerButtonGameObject);
answerButtonGameObject.transform.SetParent(answerButtonParent);
answerButtonGameObject.transform.localScale = Vector3.one;
AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton>();
answerButton.SetUp(questionData.answers[i]);
}
}