-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnity_UI_MasterScripts
More file actions
33 lines (32 loc) · 1.03 KB
/
Copy pathUnity_UI_MasterScripts
File metadata and controls
33 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class MasterScript : MonoBehaviour
{
[SerializeField] QuestionsScripts question;
[SerializeField] TextMeshProUGUI questionText;
[SerializeField] GameObject[] answerButtons;
int CorrectAnswerIndex;
[SerializeField] Sprite defaultAnswerSprite;
[SerializeField] Sprite correctAnswerSprite;
void Start()
{
questionText.text = question.GetQuestion();
for (int i = 0; i < answerButtons.Length; i++)
{
TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();
buttonText.text = question.GetAnswer(i);
}
}
public void OnAnswerSelected(int index)
{
if (index == question.GetCorrectAnswerIndex())
{
questionText.text = "Correct!";
Image buttonImage = answerButtons[index].GetComponent<Image>();
buttonImage.sprite = correctAnswerSprite;
}
}
}