hi im really new in unity, please help finish my college finale project, so i want my quiz game is stop and show score when user already answer 15 question.
i use brackleys source code in below. thank you so much
public Pertanyaan pertanyaan;
private static List unansweredQuestions;
private Pertanyaan currentQuestion;
[SerializeField] // menampilkan variable private di inspector
private Text soalText;
[SerializeField]
private Text trueAnswerText;
[SerializeField]
private Text falseAnswerText;
[SerializeField]
private Animator animator;
[SerializeField]
private float timeBetweenQuestion = 1f;
// mengecek pertanyaan yang sudah dijawab
void Start()
{
if (unansweredQuestions == null || unansweredQuestions.Count == 0)
{
unansweredQuestions = pertanyaan.ToList<Pertanyaan>();
}
SetCurrentQuestion();
}
// mengacak pertanyaan yang muncul
void SetCurrentQuestion()
{
int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions[randomQuestionIndex];
soalText.text = currentQuestion.soal;
//mengatur animasi ketika user menjawab
if(currentQuestion.jawaban)
{
trueAnswerText.text = "KAMU BENAR +5";
falseAnswerText.text = "KAMU SALAH +0";
}
else
{
trueAnswerText.text = "KAMU SALAH +0";
falseAnswerText.text = "KAMU BENAR +5";
}
}
//memberi waktu sebelum ganti soal
IEnumerator TransitionToNextQuestion()
{
unansweredQuestions.Remove(currentQuestion);
yield return new WaitForSeconds(timeBetweenQuestion);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
// memilih jawaban benar atau salah
public void UserSelectTrue()
{
animator.SetTrigger("True");
if (currentQuestion.jawaban)
{
Debug.Log("Correct");
Score.scoreValue += 5;
}
else
{
Debug.Log("Wrong ");
}
StartCoroutine(TransitionToNextQuestion());
}
public void UserSelectFalse()
{
animator.SetTrigger("False");
if (!currentQuestion.jawaban)
{
Debug.Log("Correct");
Score.scoreValue += 5;
}
else
{
Debug.Log("Wrong ");
}
StartCoroutine(TransitionToNextQuestion());
}
}