Hey. I have a problem. Script earlier work, but I wanted to make the levels of the same game and save the high score is not working. Code (csharp): using UnityEngine; using UnityEngine.UI; using System.Collections; public class ScoreManagerEasy : MonoBehaviour { public static ScoreManagerEasy OG2D; public static int score1=0; public static int bestWynik1 = 0; void start(){ OG2D = this; bestWynik1 = PlayerPrefs.GetInt ("HighScore1",0); } /*void OnGUI()// { GUI.color = Color.white; GUI.Label (new Rect (10, 30, 100, 20), "HighScre: " + bestWynik); }*/ Text text; void Awake () { text = GetComponent <Text> (); OG2D = this;// score1 = 0; bestWynik1 = PlayerPrefs.GetInt ("HighScore1",0); // } // Update is called once per frame public void Update () { text.text = "Score:"+ score1; } public void CheckHighScore() // { if (score1 > bestWynik1) { Debug.Log ("Saving Score"+bestWynik1); PlayerPrefs.SetInt("HighScore1",score1); } } }
please use [code ][/code ] tags when pasting code into the forums, really helps with the readability, there is a sticky on them at the top of the scripting forum.
public void CheckHighScore() { if (score1 > bestWynik1) { bestWynik1 = score1; // Try add that Debug.Log ("Saving Score"+bestWynik1); PlayerPrefs.SetInt("HighScore1",score1); PlayerPrefs.Save(); // And try add that } }