Answer the question
In order to leave comments, you need to log in
How to reset the record when moving to another scene?
[SerializeField] Text HighScoreText;
[SerializeField] Text scoreText;
public int score;
[SerializeField] int highScore = 0;
public bool canPickScore = true;
void Start()
{
//score = 0;
loadScores();
}
void Update()
{
HighScoreText.text = "Лучший счет: " + highScore.ToString();
if (score > highScore)
{
highScore = score;
saveScores();
}
}
public void saveScores()
{
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.Save();
}
public void loadScores()
{
highScore = PlayerPrefs.GetInt("highScore");
}
private void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "ScoreTrigger" && canPickScore == true)
{
score++;
scoreText.text = score.ToString();
saveScores();
}
}
Answer the question
In order to leave comments, you need to log in
I did this, but the problem is that the record is saved when moving to the next level
I have one... When moving from scene to scene, reset the variable, but I have no idea how to do it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question