I have a problem with setting the high score per level. I have 5 levels and per level, I want to save a high score. In my game, you have to pick up the collectibles and the time you needed to pick up all the collectibles is your high score but the high score that is made in Level 1 transfers to all the 5 levels. Has anyone a solution to this? Can you fix this with player prefs?
my code for the collectibles:
if (pickupCount <= 0)
{
player.UpdateTime();
if (PlayerPrefs.GetFloat("Highscore") > player.time)
PlayerPrefs.SetFloat("Highscore", player.time);
levelmanager.LaadVolgende();
}
and here the script “TimeKeeper”. It makes sure that my timer is only rolling when I play the levels and not the win scenes in between
public class TimeKeeper : MonoBehaviour
{
public int level1;
public int level2;
public int level3;
public int level4;
public int level5;
static TimeKeeper instance = null;
// Use this for initialization
void Start()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
instance = this;
}
}
public void UpdateTime(int time, int levelnr)
{
switch (levelnr)
{
case 2:
level1 = time;
break;
case 5:
level2 = time;
break;
case 7:
level3 = time;
break;
case 9:
level4 = time;
break;
case 12:
level5 = time;
break;
}
}
public int GeefTijd(int levelnr)
{
switch (levelnr)
{
case 3:
return level1;
case 6:
return level2;
case 8:
return level3;
case 10:
return level4;
case 13:
return level5;
default:
return 0;
}
}
I hope you understand my question and can help me with this problem.
translations:
LaadVolgende = LoadNext
levelnr = level number
Geeftijd = GiveTime