- Home /
loop through playerprefs ints and find specific one
I'm using playerprefs ints like so:
LevelC1 LevelC2 etc..
when the int is 1 it's unfinished and when tis 2 it's finished.
How can I loop through all my LevelC's till I find the one that isn't 2 anymore so let's say the player finished LevelC5=2 but LevelC6 is still 1 how can I make the script understand that I have to continue on level5 then?
Thanks!
Answer by Jan_Julius · Dec 10, 2014 at 03:50 PM
Okay I fixed it myself,
for anyone who would like to know what I did:
for(int i=0; i < 31; i++){
int LevelDone = PlayerPrefs.GetInt("LevelC"+i.ToString());
int j = i+1;
if(PlayerPrefs.GetInt("LevelC"+i.ToString()) == 2 &&
PlayerPrefs.GetInt("LevelC"+j.ToString()) == 1){
newLevel(i);
}
}
Answer by jdog98 · Dec 09, 2014 at 06:03 PM
I would recommend puting every piece you want to check into an int array. Then use something like
Public int[] levelsDone;
for(int i = 0; i < levelsDone.Length; i++){
It goes through each piece of the array and does whatever's in the {}. Reference i for what index it's checking.
Yes but I have to know when the transition from 2 to 1 is happening, I know I have to loop through it but I want to make an exception to where LevelC2 = 2 and LevelC3 = 1 and then LevelC3 get grabbed and used for something.
Your answer
Follow this Question
Related Questions
UI Slider, Save Values and Change Them 0 Answers
playerprefs and UI. 3 Answers
keep adding to playerprefs 1 Answer