Question by
Karemovich · May 27, 2018 at 09:57 PM ·
playerprefsscriptingbasicsscore systemhighscoresscoring
Hi Everyone i need to get the high score but i get last score player achieve it ,Hi Everyone i want to get The High Score of level but i get last Score Can you help me
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour {
public Transform Player;
public Text ScoreText;
public Text HighScore;
public static int PlayerHighScore;
public string score ;
// Use this for initialization
void Start () {
HighScore.text = PlayerPrefs.GetInt ("PlayerHighScore").ToString ();
}
// Update is called once per frame
void Update () {
ScoreText.text = Player.position.z.ToString("0");
score = Player.position.z.ToString("0");
int RegularScore = int.Parse (score);
if (RegularScore > PlayerHighScore) {
int PlayerHighScore = RegularScore;
PlayerPrefs.SetInt ("PlayerHighScore", PlayerHighScore);
}
}
}
Comment
Answer by Hellium · May 28, 2018 at 06:28 AM
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour {
public Transform Player;
public Text ScoreText;
public Text HighScore;
public static int PlayerHighScore;
public string score ;
// Use this for initialization
void Start () {
PlayerHighScore = PlayerPrefs.GetInt ("PlayerHighScore");
HighScore.text = PlayerHighScore.ToString ();
}
// Update is called once per frame
void Update () {
ScoreText.text = Player.position.z.ToString("0");
score = Player.position.z.ToString("0");
int RegularScore = int.Parse (score);
if (RegularScore > PlayerHighScore) {
PlayerHighScore = RegularScore;
PlayerPrefs.SetInt ("PlayerHighScore", PlayerHighScore);
}
}
}
Your answer
Follow this Question
Related Questions
Saving highscore for multiple scenes 1 Answer
Highscore and PlayerPrefs unity C# 1 Answer
High-score Saving Issue 2 Answers
displaying high score 1 Answer