[英]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.