我已经看完了 brackeys 测验,但我需要知道如何为这个游戏添加分数以检查有多少是正确的并在你回答所有问题时停止,因为在他的视频中测验一直在循环,我不知道如何停止它和怎么打分
我是一个完全的初学者,但我熟悉编码,但我不知道怎么做
这是我的游戏管理器代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEditor.UI;
using UnityEngine.UI;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using UnityEditor.Experimental.GraphView;
using UnityEngine.SocialPlatforms.Impl;
public class GameManager : MonoBehaviour
{
public GameObject NoteUI;
public GameObject Quiz1;
public Question1[] question;
private static List<Question1> unansweredQuestion;
private Question1 currentQuestion1;
[SerializeField]
private Text factPuzzle1;
[SerializeField]
private Text TrueAns;
[SerializeField]
private Text FalseANS;
[SerializeField]
Animator animator;
[SerializeField]
private float timeBetweenQuestion = 1f;
void Start()
{
if (unansweredQuestion == null || unansweredQuestion.Count == 0)
{
unansweredQuestion = question.ToList<Question1>();
}
SetCurrentQuestion();
}
void SetCurrentQuestion()
{
int randomQuestionIndex = Random.Range(0, unansweredQuestion.Count);
currentQuestion1 = unansweredQuestion[randomQuestionIndex];
factPuzzle1.text = currentQuestion1.Quiz;
if(currentQuestion1.isTama)
{
TrueAns.text = "Correct";
FalseANS.text = "False";
}else
{
TrueAns.text = "Wrong";
FalseANS.text = "Correct";
}
}
IEnumerator TransitionToNextQuestion()
{
unansweredQuestion.Remove(currentQuestion1);
yield return new WaitForSeconds(timeBetweenQuestion);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void UserInputTrue()
{
animator.SetTrigger("True");
if (currentQuestion1.isTama)
{
Debug.Log("Correct");
}
else
{
Debug.Log("eslaf");
}
StartCoroutine(TransitionToNextQuestion());
}
public void UserInputFalse()
{
animator.SetTrigger("False");
if (currentQuestion1.isTama)
{
Debug.Log("eslaf");
}
else
{
Debug.Log("Correct");
}
StartCoroutine(TransitionToNextQuestion());
}
public void Notes()
{
NoteUI.SetActive(true);
}
public void NoNotes()
{
NoteUI.SetActive(false);
}
public void TransQuiz1()
{
Quiz1.SetActive(true);
}
}