Updating the UI text

I have made a game about driving a car. And answering questions while driving. The problem is the questions do not refresh.

http://imgur.com/a/WBHhe
What i want is that the questionbox refreshes after x amount of seconds with a new question from the unaswered list.
My example codes

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

public class GameManager : MonoBehaviour {

    //Creates list of questions
    public Question[] questions;
    private static List<Question> unansweredQuestions;

    private Question currentQuestion;
  
    //Reference to text box gameobject
    [SerializeField]
    private Text factText;

    //Time between question in seconds
    [SerializeField]
    private float timeBetweenQuestions = 1f;


    void Start()
    {
        //Lists all unanswered questions so it doesn't get repeated
       if (unansweredQuestions == null || unansweredQuestions.Count == 0)
        {
            unansweredQuestions = questions.ToList<Question>();
        }

        getRandomQuestion();
    }

    //Picks a random Question
    void getRandomQuestion()
    {
        int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
        currentQuestion = unansweredQuestions[randomQuestionIndex];

        factText.text = currentQuestion.fact;

    }

    //Transistion to new question
    IEnumerator TransisitionToNextQuestion()
    {
        unansweredQuestions.Remove(currentQuestion);

        yield return new WaitForSeconds(timeBetweenQuestions);

        InvokeRepeating(currentQuestion.fact, 10f, 10f);

    }

    //True
    public void UserSelectTrue()
    {
        if (currentQuestion.isTrue)
        {
            Debug.Log("CORRECT!");
        }
        else
        {
            Debug.Log("FOUT!");
        }

        StartCoroutine(TransisitionToNextQuestion());
    }

    // False
    public void UserSelectFalse()
    {
        if (!currentQuestion.isTrue)
        {
            Debug.Log("CORRECT!");
        }
        else
        {
            Debug.Log("FOUT!");
        }

        StartCoroutine(TransisitionToNextQuestion());
    }
}

At a quick glance, instead of this in you coroutine;

 InvokeRepeating(currentQuestion.fact, 10f, 10f);

call getRandomQuestion instead.

2 Likes