[英]How put score in a quizgame in unity3d
我如何在每次問答游戲中保持分數不變,這是將分數重置為零的問題,這是我的方法
public void UserSelectTrue()
{
animator.SetTrigger("True");
if (currentQuestion.isTrue)
{
countScore = countScore + 2;
SetScoreText();
Debug.Log("Correct");
}
else
{
Debug.Log("Wrong");
}
StartCoroutine(TransitionToNextQuestion());
}
public void UserSelectFalse()
{
animator.SetTrigger("False");
if (!currentQuestion.isTrue)
{
countScore = countScore + 2;
SetScoreText();
Debug.Log("Correct");
}
else
{
Debug.Log("Wrong");
}
StartCoroutine(TransitionToNextQuestion());
}
您可以將Singleton模式與DontDestroyOnload
一起使用,以僅在場景之間保留對象的一個實例,請注意以下事實: DontDestroyOnload
意味着在加載新場景時不會破壞對象
public class ScoreManager: MonoBehaviour
{
private static ScoreManager_instance ;
void Awake()
{
//we will make an instance if we don't have one yet
if(!_instance)
_instance = this ;
//if we have an instance we don't need this one so we Destroy it
else
Destroy(this.gameObject) ;
//we can keep this object between the scense with DontDestroyOnLoad
DontDestroyOnLoad(this.gameObject) ;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.