Hey Forum! Could someone help me with creating an individual highscore counter?
I am trying to make a puzzle game with 900 stages, the menu’s and stages are already working but I cannot get the Highscore to work. What I am trying to achieve for almost two days now is that I want to be able to select a level, get a score, save it for that stage, move on to the next stage or back to the main menu and then go to the next stage and repeat that process.
But the problem I am having right now is that whenever I save the score that I got for the first level hops over to the next stage aswell. For example:
I got 100 points in stage 1. My score gets saved and I go back to the main menu.
I select stage 2.
Before playing, my highscore for stage 2 is now already 100.
I searched around the web for a while and I couldn’t really find a similiar situation , but I couldn’t really find what I wanted so I decided to ask for help.
I am using an public static int on the main menu to select and remember the stage number. Then in the 2nd scene I read that number and I try to put it into an array :
This way my array should grow according to the number of stages so that I can always add as much stages as I like.
Then I have the Score which is the amount of score you have during the gameplay.
When you finish the stage, I check the score you have and replace the highscore if you beat your previous time.
The name “i” does not exist in the current context
cannot convert “object” expression to type “string”
argument # 1 cannot convert "object " expression to type “string”
twice for both :
High_Score.text = "Current Highscore = "+ PlayerPrefs.GetFloat(“HScore[” + i + “]”);
and
PlayerPrefs.SetFloat(“HScore[” + i + “]”, Highscore);
I think I made a mistake with the array or something, it keeps giving errors with the “i” whenever I try something with it.
These are basic C# problems that you’re battling with, and you are not ready to be making games in Unity yet.
I’d suggest buying a C# book and understanding the basics before trying to make games.