how can i maintain the score in my quiz game every time it change it's question it also reset the score to zero here is my method
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());
}
you can use Singleton pattern with DontDestroyOnload
to keep only one instance of the object between the scenes, be aware of the fact that DontDestroyOnload
means the object won't be destroyed when a new scene loads
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) ;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.