My Game: True or False Quiz with randomized questions
My Goal: Score would add whenever the player hit the correct answer
My Problem: If I hit the correct answer, the score would be 1 but turns immediately to 0.
HERE IS MY CODE:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.SceneManagement;
public class GameScript : MonoBehaviour {
public Question[] questions;
private static List<Question> uquestions;
private Question cquestion;
public int currentscore = 0;
[SerializeField]
private Text scoretxt;
[SerializeField]
private Text facttxt;
[SerializeField]
private Text truetxt;
[SerializeField]
private Text falsetxt;
[SerializeField]
private float delay = 1f;
[SerializeField]
private Animator animator;
void Start()
{
if (uquestions == null || uquestions.Count == 0)
{
uquestions = questions.ToList<Question>();
}
SetCurrentQuestion();
}
void SetCurrentQuestion()
{
int rquestion = Random.Range (0, uquestions.Count);
cquestion = uquestions [rquestion];
scoretxt.text = currentscore.ToString();
facttxt.text = cquestion.fact;
uquestions.RemoveAt (rquestion);
if (cquestion.correct) {
truetxt.text = "CORRECT";
falsetxt.text = "WRONG.";
}
else
{
truetxt.text = "WRONG";
falsetxt.text = "CORRECT";
}
//scoretxt.text = currentscore.ToString();
}
IEnumerator TransToQuestion()
{
uquestions.Remove(cquestion);
yield return new WaitForSeconds (delay);
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
}
public void UserSelectTrue()
{
animator.SetTrigger ("True");
if (cquestion.correct)
{
currentscore++;
Debug.Log ("Correct.");
}
else
{
Debug.Log ("Wrong.");
}
StartCoroutine(TransToQuestion());
}
public void UserSelectFalse()
{
animator.SetTrigger ("False");
if (!cquestion.correct)
{
currentscore++;
Debug.Log ("Correct.");
}
else
{
Debug.Log ("Wrong.");
}
StartCoroutine(TransToQuestion());
}
}
Please help me guysss!!