Okay so I have multiple scripts for each category cause I couldn’t figure out how to have the questions loading from just one just one script, but that’s not really important for my issue cause what I did was working fine. Anyway! So here’s the script for the Games category high score:
So first of all, the code that gets, saves, loads, etc the high score:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GamesController : MonoBehaviour {
public RoundData[] gamesRoundData;
private HighScoreGamesManager gamesScore;
// Use this for initialization
void Start () {
DontDestroyOnLoad (gameObject);
SceneManager.LoadScene ("MenuScene");
LoadGamesScore ();
}
public RoundData GetCurrentRoundData () {
return gamesRoundData [0];
}
// Update is called once per frame
void Update () {
}
public void NewGamesScore (int newGamesScore) {
if (newGamesScore > gamesScore.gameshighscore) {
gamesScore.gameshighscore = newGamesScore;
SaveGamesScore ();
}
}
private void LoadGamesScore () {
gamesScore = new HighScoreGamesManager ();
if (PlayerPrefs.HasKey ("gameshighscore"))
{
gamesScore.gameshighscore = PlayerPrefs.GetInt ("gameshighscore");
}
}
public int GetGamesScore() {
return gamesScore.gameshighscore;
}
private void SaveGamesScore () {
PlayerPrefs.SetInt ("gameshighscore", gamesScore.gameshighscore);
}
}
Then the storing the gameshighscore, which originally I had ALL of them, gameshighscore, sportshighscore, etc all in one script, but I separated them all to see if that would work, but it did nothing, anyway here’s the games one:
public class HighScoreGamesManager {
public int gameshighscore;
}
And here’s for displaying the Games High Score (also separated all the categories with another attempt, didn’t fix anything) so it’s just the games category right now:
public Text gamesHighScoreDisplayer;
void Awake ()
{
gamesController = FindObjectOfType<GamesController> ();
gamesHighScoreDisplayer.text = gamesController.GetGamesScore ().ToString ();
}
And this part in the actual game code which sends the new score to be saved:
public void EndRound () {
isRoundActive = false;
dataController.NewGamesScore (gamesPlayerScore);
questionDisplay.SetActive (false);
roundEndDisplay.SetActive (true);
}
And all of my other codes are the exact same, the ONLY difference is replacing “games” with the appropriate category. I’ve gone over that way too many times and there’s definitely no errors with that part. For some reason, no matter what I’ve changed and tried, it continues to give all other categories half the high score of whatever one I play.
I’m sure there has to be some simple solution to this that I’m missing?