why when i play my game (quiz master) its cannot be interact??but the timer is stil running
btw sorry for my bad english, im still learning
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class Quiz : MonoBehaviour
{
[Header("Question")]
[SerializeField]TextMeshProUGUI questionText;
[SerializeField]QuestionSO question;
[Header("Answer")]
[SerializeField] GameObject[] answerButtons;
int correctAnswerIndex;
[Header("Button Color")]
[SerializeField] Sprite defaultAnswerSprite;
[SerializeField] Sprite correctAnswerSprite;
[Header("Timer")]
[SerializeField] Image timerImage;
Timer timer;
bool hasAnsweredEarly = false;
void Start()
{
timer = FindObjectOfType<Timer>();
GetNextQuestion();
}
void Update()
{
timerImage.fillAmount = timer.fillFraction;
if(timer.loadNextQuestion)
{
hasAnsweredEarly = false;
GetNextQuestion();
timer.loadNextQuestion = false;
}
else if(!hasAnsweredEarly && !timer.isAnsweringQuestion)
{
DisplayAnswer(-1);
SetButtonState(false);
}
}
public void OnAnswerSelected(int index)
{
DisplayAnswer(index);
SetButtonState(false);
timer.cancelTimer();
hasAnsweredEarly = true;
}
void DisplayAnswer(int index)
{
Image buttonImage;
if (index == question.getCorrectAnswerIndex())
{
questionText.text = "BENARRR!!";
buttonImage = answerButtons[index].GetComponent<Image>();
buttonImage.sprite = correctAnswerSprite;
}
else
{
correctAnswerIndex = question.getCorrectAnswerIndex();
string correctAnswer = question.getanswer(correctAnswerIndex);
questionText.text = "Yahhh, tapi jawaban yang benarnya adalah :\n" + "\n" + correctAnswer;
buttonImage = answerButtons[correctAnswerIndex].GetComponent<Image>();
buttonImage.sprite = correctAnswerSprite;
}
}
void GetNextQuestion()
{
SetButtonState(true);
SetDefaultButtonSprites();
DisplayQuestion();
}
void DisplayQuestion()
{
questionText.text = question.getQuestion();
for (int i = 0; i < answerButtons.Length; i++)
{
TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();buttonText.text = question.getanswer(i);
}
}
void SetButtonState(bool state)
{
for (int i = 0; i< answerButtons.Length; i ++)
{
Button button = answerButtons[i].GetComponent<Button>();
button.interactable = state;
}
}
void SetDefaultButtonSprites()
{
for (int i = 0; i < answerButtons.Length; i++)
{
Image buttonImage = answerButtons[i].GetComponent<Image>();
buttonImage.sprite = defaultAnswerSprite;
}
}
}