Need Help with High Score Please.
I have 2 scripts, One "ScoreManager" for my Score, and another for my High Score names "HighscoreScript". Currently they Operate fine and transfer to next scene, however, I would Like the Highscore data to remain even after restart and the Score data to reset upon restart. Im sure Im just confusing myself, but would appreciate any help.
This in my HighscoreScript
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class HighscoreScript : MonoBehaviour {
Text text;
public static int Highscore;
// Use this for initialization
void Start ()
{
Highscore= PlayerPrefs.GetInt ("Highscore", Highscore);
text = GetComponent<Text> ();
}
// Update is called once per frame
void Update ()
{
text.text = "Highscore: " + ScoreManager.Score;
if (ScoreManager.Score >= Highscore) {
Highscore = ScoreManager.Score;
} else
Highscore = PlayerPrefs.GetInt ("Highscore", Highscore);
PlayerPrefs.SetInt ("Highscore", Highscore);
PlayerPrefs.Save ();
}
}
and this is ScoreManager for Score
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
Text text;
public static int Score;
// Use this for initialization
void Start ()
{
text = GetComponent<Text>();
if (Score>0)
{
PlayerPrefs.GetInt ("Score", Score);
}
else Score = 0;
}
// Update is called once per frame
void Update ()
{
text.text = "Score: " + Score;
PlayerPrefs.SetInt ("Score", Score);
}
}
Any Help or Pointer would be appreciated.
Looking for the same myself. I have a game controller that I used from the Unity space shooter tutorial and it has spawning and scoring and works but doesn't cover high score. Why have a space shooter game and not keep a high score? Also, I'm not a programmer and want to have fun building my own game but there aren't enough tutorials/examples that I can understand since they all have different ways of doing things. I'm getting good with Unity but not c# and just want to save my score.