Question by
Fullmetal16 · Jun 01, 2017 at 09:45 AM ·
unity 5scripting problemuitextcodepage
Changing the UI Text
So I want to update the gui when a question is answered. i looked up a tutorial however the guy in the tutorial reloads the entire scene. What I'm trying to do is to update the gui text with a different question. The code I used is below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
public Question[] questions;
private static List<Question> unansweredQuestions;
private Question currentQuestion;
[SerializeField]
private Text factText;
[SerializeField]
private float timeBetweenQuestions = 1f;
void Start()
{
if (unansweredQuestions == null || unansweredQuestions.Count == 0)
{
unansweredQuestions = questions.ToList<Question>();
}
getRandomQuestion();
}
void getRandomQuestion()
{
int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions[randomQuestionIndex];
factText.text = currentQuestion.fact;
}
IEnumerator TransisitionToNextQuestion()
{
unansweredQuestions.Remove(currentQuestion);
yield return new WaitForSeconds(timeBetweenQuestions);
//Where i think the code should be put to change the text around
}
public void UserSelectTrue()
{
if (currentQuestion.isTrue)
{
Debug.Log("CORRECT!");
}
else
{
Debug.Log("FOUT!");
}
StartCoroutine(TransisitionToNextQuestion());
}
public void UserSelectFalse()
{
if (!currentQuestion.isTrue)
{
Debug.Log("CORRECT!");
}
else
{
Debug.Log("FOUT!");
}
StartCoroutine(TransisitionToNextQuestion());
}
}
Comment
Your answer
Follow this Question
Related Questions
UI Text: Words at end of line jumping to next line 0 Answers
OnGUI behind UI? 0 Answers
Text alignment not working 2 Answers
problem with Adjustable Character Spacing script in Unity 5.4 0 Answers
UI Text is Blurry in RenderTexture 1 Answer