I have it to where the high score is saved but when I try to display it, i need to play the game first then it will show up later, I don’t want it to be 0 then what ever number it is.
here a small part of the script with the high score (C#)
public static int score;
//Highscore
public static int highScore;
string highScoreKey = "HighScore";
void OnDisable(){
if (score > highScore) {
PlayerPrefs.SetInt (highScoreKey, score);
PlayerPrefs.Save ();
}
}
And here is the script where I display the high score
//HighScore
GUI.Box (new Rect (10, 10, 200, 80), "Highscore Table");
GUI.Box (new Rect (10, 30, 200, 20), Player_Normal.highScoreToString ());
There should be dot before “ToString”, but it is not important.
Replace “Player_Normal.highScoreToString ()” to "PlayerPrefs.GetInt (“HighScore”).ToString ();
I ended up doing this and It works now.
using UnityEngine;
using System.Collections;
public class MainMenu : MonoBehaviour {
//Normal
public string normalLevel;
public string Normal;
string highScoreKey = "HighScore";
// Use this for initialization
void Start () {
Normal = PlayerPrefs.GetInt (highScoreKey).ToString();
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if (GUI.Button (new Rect (Screen.width / 2 - 100 , Screen.height / 2 - 100, 200, 40), "[N]ormal")) {
Application.LoadLevel (normalLevel);
}
if (GUI.Button (new Rect (Screen.width / 2 - 100 , Screen.height / 2 - 60, 200, 40), "~~tore")) {~~
~~ store();~~
~~ }~~
~~ if (GUI.Button (new Rect (Screen.width / 2 - 100 , Screen.height / 2 - 20, 200, 40), “[Q]uit”)) {~~
~~ Application.Quit ();~~
~~ }~~
~~ //HighScore~~
~~ GUI.Box (new Rect (10, 10, 200, 80), “Highscore Table”);~~
~~ GUI.Box (new Rect (10, 30, 200, 20), "Normal: " + Normal);~~
~~ }~~
~~ void store(){~~
~~ }~~
}