- Home /
How Do You Have Multiple High Scores For 1 GameOverScene?
So I have multiple levels, each with their own PlayerPrefs that saves the Player's score when they die. After they die they are taken to a GameOver scene that shows them their score. The problem is that the GameOver Scene only loads the first level's score because it only has one script that does that. What I want to know, is how can I after or before the player dies, disable the game object or script of the first high score in the GameOver scene, and then enable a game object or script that shows the high score depending on the level I'm in(In the GameOver Scene). I hope I'm making sense.
In concept I think it would go something like this: First I create an array of game objects, and when a certain scene is loaded, enable a certain game object. But how can that work? Through prefabs maybe?
By the way, I could always just create a bunch of GameOver scenes for each level, but that would be laziness on my part big time(unless it recommend which I highly doubt).
In an effort to help you, I'll just say these for your consideration:
I understand that you want to have a GameOver scene that will show the High Scores for each level the player has played. However, most things you say just don't make sense, and/or the way you are planning to do things is not "Best Practice". For instance:
Why have multiple PlayerPrefs? why can't each level save the high score with a different name, in the same PlayerPrefs? e.g. HighScore1 corresponding to level 1, HighScore2 corresponding to level 2, etc.
Why have a script in the GameOver Scene that only loads the first level's score? Why can't a single script load all High Scores?
Why have multiple GameOver Scenes?
If you want to know how to enable or disable GameObjects you should reference the documentation:
http://docs.unity3d.com/ScriptReference/GameObject.SetActive.html
Thanks for your reply. I'll answer your questions now:
If I understand you correctly, then that's because I want to be able to go to a scores menu and see all the different scores I have on each level. Every time I get a higher score than before, it overwrites the previous score. I guess you can say it's because of the way my PlayerPrefs is set up/inexperience that stops me from using just one Player Prefs. I'm talking about Player Prefs set integers by the way.
I don't know how to load all high scores. Probably something like PlayerPrefs get all int or something.
That was just a thought. I do not plan on having multiple GameOver scenes.
Thank you but I already know how to do that. I was asking if I can activate game objects from a different scene.
Answer by MKayJay · Jan 14, 2015 at 11:06 PM
If you're comfortable working with arrays, you might want to consider using PlayerPrefsX. It's an extension to playerPrefs that allows you to save arrays. You can find it here where you can simply copy/paste the code from and then use that class to handle your PlayerPrefs. I use that for my current project. This way you can have an entire array for each level, or use the entire array to store the score from all the levels. Personally I find it much easier to handle a lot of highscores and stuff with arrays.
Wow looks complicated because the short explanation is in JavaScript, but thank you for the post. I'll see if I can intergrade it properly. Thanks again.
Your answer
Follow this Question
Related Questions
c# destroy gameobject on 0 hp 2 Answers
Nullreferencexception using PlayerPrefs.GetInt and GetString 1 Answer
How to Load PlayerPrefs from a different scene 1 Answer
Readd GameObject to scene (to restore it) 0 Answers
Unity 3d(Space) Questions 1 Answer