Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

HighScore not showing up C#

$
0
0
HI, I'm trying to make a high score thingy which stores the highest distance the player has traveled (which is payer.position.z). It shows up on the game over screen after the player dies and an option to restart the game which loads the game screen again. here's my code:`public class Score : MonoBehaviour { public Transform player; public Text scoreText; public Text highScoreText; public Text curScoreText; public static float score; bool playerDied; private void Start() { playerDied = false; highScoreText.text = PlayerPrefs.GetFloat("HighScore", 0).ToString(); } private void Update() { if (playerDied == false) { score = player.position.z; scoreText.text = score.ToString("0"); curScoreText.text = score.ToString("0"); } } public void HighScore() { if (score > PlayerPrefs.GetFloat("HighScore", 0)) { PlayerPrefs.SetFloat("HighScore", score); highScoreText.text = score.ToString(); } } }`

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>