Destroy question if its already asked

Hello Everyone, I made a Quiz Game thanks to the Unity Tutorial Quiz Game - Intro and Setup [1/8] Live 2016/11/14 - YouTube.

Now I have put this code ‘int questionIndex = Random.Range(0, questionPool.Length -1);’ in the script under ‘private void ShowQuestion()’

To pick up random questions, it works. But its take the same questions that is just asked. I want it to go like question is asked and don’t come back in the round and go on with the new questions I am 3 days trying to fix this problem but nothing. I hope you guys can help me out.

Here is the script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Linq;

public class GameController : MonoBehaviour
{

    public int playerHealth = 30;
    int damage = 10;
    public Scrollbar HealthBar;
    public float Health = 30;

    public AudioClip Goed;
    public AudioClip Fout;
    public AudioClip klikklak;

    public Text TotalscoreDisplayText;
    public Text questionDisplayText;
    public Text scoreDisplayText;
    public Text timeRemainingDisplayText;

    public SimpleObjectPool answerButtonObjectPool;
    public Transform answerButtonParent;

    public GameObject questionDisplay;
    public GameObject roundEndDisplay;

    public Text HighScoreText;

    AudioSource GOED;
    AudioSource FOUT;
    AudioSource KlikKlak;

    private DataController dataController;
    private RoundData currentRoundData;
    private QuestionData[] questionPool;

    private bool[] alreadyAskedQuestions;

    private bool isRoundActive;
    private float timeRemaining;
    private int questionIndex;
    private int playerScore;

    private List<GameObject> answerButtonGameObjects = new List<GameObject>();
    

    void Awake()
    {
        GOED = GetComponent<AudioSource>();
        FOUT = GetComponent<AudioSource>();
        KlikKlak = GetComponent<AudioSource>();
    }

    // Use this for initialization
    void Start()
    {
        dataController = FindObjectOfType<DataController>();
        currentRoundData = dataController.GetCurrentRoundData();
        questionPool = currentRoundData.questions;
        UpdateTimeRemainingDisplay();

        playerScore = 0;
        questionIndex = 0;

        ShowQuestion();
        isRoundActive = true;

        HighScoreText.text = " " + ((int)PlayerPrefs.GetFloat("HighScore")).ToString();
    }

    private void ShowQuestion()
    {

        RemoveAnswerButtons();

        int questionIndex = Random.Range(0, questionPool.Length - 1);          
        
        QuestionData questionData = questionPool[questionIndex];
        questionDisplayText.text = questionData.questionText;

        for (int i = 0; i < questionData.answers.Length; i++)
        {
            GameObject answerButtonGameObject = answerButtonObjectPool.GetObject();
            answerButtonGameObjects.Add(answerButtonGameObject);
            answerButtonGameObject.transform.SetParent(answerButtonParent);

            AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton>();
            answerButton.Setup(questionData.answers*);*

timeRemaining = currentRoundData.timeLimitInSeconds;
}
}

private void RemoveAnswerButtons()
{
while (answerButtonGameObjects.Count > 0)
{
answerButtonObjectPool.ReturnObject(answerButtonGameObjects[0]);
answerButtonGameObjects.RemoveAt(0);
}
}

private void UpdateTimeRemainingDisplay()
{
timeRemainingDisplayText.text = "TIJD: " + Mathf.Round(timeRemaining).ToString();
}

public void AnswerButtonClicked(bool isCorrect, bool isNotCorrect, float value)
{
if (isNotCorrect)
{
playerHealth -= damage;
FOUT.PlayOneShot(Fout);
Health -= value = 10;
HealthBar.size -= Health / 40f;
if (Health == 10)
{
KlikKlak.PlayOneShot(klikklak);
}
}
if (isCorrect)
{
GOED.PlayOneShot(Goed);
playerScore += currentRoundData.pointsAddedForCorrectAnswer;
scoreDisplayText.text = "SCORE: " + playerScore.ToString();
TotalscoreDisplayText.text = "Totaal " + playerScore.ToString();
}
if (questionPool.Length > questionIndex + 1)
{
questionIndex++;
ShowQuestion();
}
else
{
EndRound();
}
}

public void EndRound()
{
if (PlayerPrefs.GetFloat(“HighScore”) < playerScore)
PlayerPrefs.SetFloat(“HighScore”, playerScore);
isRoundActive = false;
questionDisplay.SetActive(false);
roundEndDisplay.SetActive(true);
}

public void ReturnToMenu()
{
SceneManager.LoadScene(“MenuScreen”);
}

// Update is called once per frame
void Update()
{
if (isRoundActive)
{
timeRemaining -= Time.deltaTime;
UpdateTimeRemainingDisplay();
if (timeRemaining <= 0f)
{
EndRound();
}
else
if (playerHealth <= 0)
{
playerHealth = 0;
EndRound();
}
}
}
}

Ok so this is very skeleton code with placeholder QuestionData since I don’t have access to all your scripts. But it should be enough to show you how you can use a list to store your questions, removing each questions as you ask it so that it cannot be asked again (since it is no longer in the list, and the list is where we randomly pick questions from).

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{

    private List<QuestionData> m_Questions;

    void Start()
    {
        // I have to use an empty list since I dont have your currentRoundData but you do, so just create the list by passing it the array.
        m_Questions = new List<QuestionData>(/*currentRoundData.questions*/);
        ShowQuestion(GetQuestion());
    }

    private void ShowQuestion(QuestionData lQuestion)
    {
        // Show your question etc.
    }


    public void AnswerQuestionButton(bool isCorrect, float value)
    {
        // Note since correct and incorrect cannot both be true, you only need one argument as the other is implied.
        if (isCorrect)
        {
            // do your stuff here for a good answer.
        }
        else
        {
            // the player is not so smart this time. 
        }

        if (m_Questions.Count > 0)
        {
            // Show next question
            ShowQuestion(GetQuestion());
        }
        else
        {
            // No more questions, game over i guess?
        }
    }


    private QuestionData GetQuestion()
    {
        // Grab a question from the list (i'm using a random one, you could do them in order, up to you).
        QuestionData lQuestion = m_Questions[Random.Range(0, m_Questions.Count)];

        // Remove the question from the list, so that it cannot be asked again.
        m_Questions.Remove(lQuestion);

        // Return the selected question.
        return lQuestion;
    }



    public class QuestionData
    {
        public string question;
        public string answer;
    }

}