0

I'm building a top-down tron-style game, and after you finish a gamemode, an arcady 3 letter name input pops up, these go through the alphabet and some numbers. After you input your name, it checks if the name is already in playerprefs and it adds one point to that score. So far so good.

I was ready to start retrieving the data so i could build something like a leaderboard system in another scene, but then I quickly learned that it is not possible to iterate through all playerprefs to retrieve them. I have tried a couple of ways to resolve this problem but it all ended in me having to have the name that the user has inputted to retrieve the associated score.

Now this may sound like a newbie question (and it kinda is, this is my first unity project), but how would one resolve this problem. I have read bits and pieces about serialisation, but it is still very unclear what that actually is and how I could use it for my project

Just for reference, this is the code I use to store my data right now,

 void saveData()
    {
        
        string nameRes = A.text + B.text + C.text;
        int score = PlayerPrefs.GetInt(nameRes);
        scoresafe++;

        if (scoresafe == 1)
        {
            score++;
        }
        else
        {
            SceneManager.LoadScene("MainMenu");
        }
        Debug.Log("totalscore:" + score + " scoresafesystem: " + scoresafe);
        PlayerPrefs.SetInt(nameRes, score);
        
        PlayerPrefs.Save();

    }

Any help would be much appreciated

Diado
  • 2,229
  • 3
  • 18
  • 21
  • I am not a Unity expert, but it doesn't sound like the highscore table is really a "player preference". Sounds more like something that should be stored in another data store (such as a database). – fredrik Jul 20 '20 at 11:16
  • yes i totally agree with you, only thing is that this is the way some tutorial i used teached me how to do it, thats why i'm asking what a better way is to achieve what i want – Jelmer vd Bij Jul 20 '20 at 11:19
  • There are alot of ways to accomplish this, which ones good or bad is as far as I'm concerned off-topic as opinion-based here on SO. You should look up various data storage methods for yourself and make a decision about which one suits your needs for this instance the best. – fredrik Jul 20 '20 at 11:30

0 Answers0