- Home /
Switch Between Images
Hello i have been working on making a quiz game in unity that consists of True or False , at the moment i am using text to display whether the answer is wrong or correct, but i would like to use images instead, but i have no idea how to go about it . Any help is Appreciated . Here is my game manger code . Thanks in advance.
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using System.Linq; using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
public Question[] questions;
private static List<Question> unansweredQuestions;
private Question currentQuestion;
[SerializeField]
private Text factText;
[SerializeField]
private Text trueAnswerText;
[SerializeField]
private Text falseAnswerText;
[SerializeField]
private Animator animator;
[SerializeField]
private float TimeBetweenQuestions = 1f;
void Start()
{
if (unansweredQuestions == null || unansweredQuestions.Count == 0)
{
unansweredQuestions = questions.ToList<Question>();
}
SetCurrentQuestion();
}
void SetCurrentQuestion ()
{
int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions[randomQuestionIndex];
factText.text = currentQuestion.fact;
if (currentQuestion.isTrue)
{
trueAnswerText.text = "Like A Boss!";
falseAnswerText.text = "False";
}else
{
trueAnswerText.text = "WRONG";
falseAnswerText.text = "Like A Boss!";
}
}
IEnumerator TransitionToNextQuestion ()
{
unansweredQuestions.Remove(currentQuestion);
yield return new WaitForSeconds(TimeBetweenQuestions);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void UserSelectTrue ()
{
animator.SetTrigger("True");
if (currentQuestion.isTrue)
{
Debug.Log("LIKE A BOSS!");
} else
{
Debug.Log("WRONG!");
}
StartCoroutine(TransitionToNextQuestion());
}
public void UserSelectFalse()
{
animator.SetTrigger("False");
if (!currentQuestion.isTrue)
{
Debug.Log("LIKE A BOSS!");
}
else
{
Debug.Log("WRONG!");
}
StartCoroutine(TransitionToNextQuestion());
}
}
Comment
Your answer
Follow this Question
Related Questions
Rect Transform to World Position Conversion 2 Answers
Scale UI Image source image 1 Answer
scaling NGUI UItexture to screen size 0 Answers
Question about an inventory system idea 2 Answers
Warp Image/Sprite Anchors? 1 Answer