- Home /
Question by
anishbatman5432 · Aug 03, 2020 at 11:20 AM ·
scorescore systemhighscoresscoreboard
my code is suppose to store high score and its storing recent score insted and it wont stop if game over and it has an score counter as well plzz help
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class score3 : MonoBehaviour { public Text highScore; float timeBtwIncreases = 1f; int scoreAmount = 0; public int score;
// Start is called before the first frame update
private void Start()
{
highScore.text = PlayerPrefs.GetInt("Higcore",0).ToString();
}
// Update is called once per frame
void Update()
{
timeBtwIncreases -= Time.deltaTime;
if (timeBtwIncreases <= 1f)
{
scoreAmount += 10;
if( scoreAmount > PlayerPrefs.GetInt("HighSore", 0))
{
PlayerPrefs.SetInt("HighScore", scoreAmount);
highScore.text = scoreAmount.ToString();
}
timeBtwIncreases = 1f;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to create a HighScore using playerprefs based on passed time? 1 Answer
Scoring System 3 Answers
How to save score for survival time? 1 Answer