Question by
jlgipoleo24 · Feb 03, 2017 at 08:52 PM ·
androidunity 5scorescore systemquiz
How to add scoring system with this type of codes? This is a True or False Game. Answers are very much appreciated. :)
I'm trying to ad a scoring to my simple quiz game. I try to customize my codes but the score always reset to zero when scene loads to another. Thank you for your answers. I'm just a beginner. :)
Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Linq;
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 = 2f;
[SerializeField]
public Text scoreText;
[SerializeField]
public Text bestText;
public int scoreCount=0;
public int bestCount;
public bool scoreIncreasing;
void Start()
{
if (unansweredQuestions == null || unansweredQuestions.Count == 0)
{
unansweredQuestions = questions.ToList<Question>();
}
SetCurrentQuestion ();
Debug.Log (currentQuestion.fact + " is " + currentQuestion.isTrue);
}
void SetCurrentQuestion ()
{
int randomQuestionIndex = Random.Range (0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions [randomQuestionIndex];
factText.text = currentQuestion.fact;
if (currentQuestion.isTrue)
{
trueAnswerText.text = "CORRECT!";
falseAnswerText.text = "WRONG!";
} else
{
trueAnswerText.text = "WRONG!";
falseAnswerText.text = "CORRECT!";
}
}
IEnumerator TransitionToNextQuestion ()
{
unansweredQuestions.Remove (currentQuestion);
yield return new WaitForSeconds (timeBetweenQuestions);
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
}
public void UserSelectTrue ()
{
animator.SetTrigger ("True");
if (currentQuestion.isTrue) {
Debug.Log ("CORRECT!");
} else
{
Debug.Log ("WRONG!");
}
DontDestroyOnLoad (gameObject);
StartCoroutine (TransitionToNextQuestion ());
}
public void UserSelectFalse ()
{
animator.SetTrigger ("False");
if (!currentQuestion.isTrue) {
Debug.Log ("CORRECT!");
} else
{
Debug.Log ("WRONG!");
}
DontDestroyOnLoad (gameObject);
StartCoroutine (TransitionToNextQuestion ());
}
public void LoadScene(string name){
Application.LoadLevel (name);
}
public void QuitGame(){
Application.Quit();
}
}
In my code I just initialize the variable for the score. What to do next?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612110225im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scoring Points with UI Text 0 Answers
Highscore table C# HELP!!! 0 Answers
voice recognition 2 Answers
Android game updater (autopatch) 0 Answers
How to publish 400mb size apk to playstore exported from unity in android studio? 0 Answers