Hi… i’m new in unity and i want to make a quiz game and here is the script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
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 = "Hebat";
FalseAnswerText.text = "Maaf";
}else
{
TrueAnswerText.text = "Maaf";
FalseAnswerText.text = "Hebat";
}
}
void CallGameOverScene()
{
SceneManager.LoadScene("GameOverScene");
Application.LoadLevel("GameOverScene");
}
IEnumerator TransitionToNextQuestion()
{
unansweredQuestions.Remove(currentQuestion);
yield return new WaitForSeconds(TimeBetweenQuestions);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void UserSelectTrue()
{
animator.SetTrigger("Benar");
if (currentQuestion.isTrue)
{
Debug.Log("Hebat!");
StartCoroutine(TransitionToNextQuestion());
}
else
{
Debug.Log("Maaf");
CallGameOverScene();
}
}
public void UserSelectFalse()
{
animator.SetTrigger("Salah");
if (!currentQuestion.isTrue)
{
Debug.Log("Hebat!");
StartCoroutine(TransitionToNextQuestion());
}
else
{
Debug.Log("Maaf");
CallGameOverScene();
}
}
}
how to make a scoring and final score on game over scene ?
Thx before
Ps; i’m following tutorial brackeys to make this script