Hey - So, I actually already asked this, but I didn’t quite understand, and I’ve spent a fair few hours googling, I’m sure I have missed something basic that I shouldn’t of overlooked - my code for this has gone through quite a few iterations, the best I could do (and I don’t understand why it was doing it) was my Highscore was permanently set to “31” for a reason I couldn’t tell.
I’m attempting to save my highscore so I can keep it each time the game restarts.
This is my code underneath.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class highScoreController : MonoBehaviour {
public Text highScore;
public GameObject scoreTimer;
score myScore;
public int myHighScore;
void Start ()
{
GameObject scoreTimer = GameObject.Find("scoreTimer");
myScore = scoreTimer.GetComponent<score>();
highScore.GetComponent<Text>().text = "HighScore: " + myHighScore.ToString();
myHighScore = PlayerPrefs.GetInt("highs");
}
// Update is called once per frame
void Update ()
{
if (PlayerPrefs.GetInt("highs") > myHighScore)
{
myHighScore = PlayerPrefs.GetInt("highs");
StoreHighscore();
}
else
highScore.GetComponent<Text>().text = "HighScore: " + myHighScore.ToString();
}
void StoreHighscore()
{
if (myScore.scoreme > myHighScore)
{
PlayerPrefs.SetInt("highs", myHighScore);
PlayerPrefs.Save();
}
}
}
Sorry for submitting more-or-less the same question twice, but I’m extremely stuck on this…