UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create an advanced score counter for players"
public class Score : MonoBehaviour { // SingleTon Pattern public static Score instance; private int score; private int highScore; public Text scoreText; public Text gameOverScoreText; public Text highScoreText; public Text pauseScoreText; private void Start() { if (instance == null) { instance = this; } highScore = PlayerPrefs.GetInt("highscore", highScore); highScoreText.text = highScore.ToString(); } private void Update() { scoreText.text = score.ToString(); if (score > highScore) { highScore = score; highScoreText.text = highScore.ToString(); PlayerPrefs.SetInt("highscore", highScore); } } public void AddScore() { score = 1; scoreText.text = score.ToString(); gameOverScoreText.text = score.ToString(); pauseScoreText.text = score.ToString(); } }