Hello I’m trying to make a little 2D platform game and at the moment I have this code when I end the level:
PlayerPrefs.SetInt ("countingCoins", theLevelManager.countingCoins);
PlayerPrefs.SetInt ("PlayerLives", theLevelManager.currentLives);
I am using the getInt
to get values and carry them over level but they keep adding so my currentlives
goes to more than I intend,on my LevelManager script I use this code on void start();
void Start () {
thePlayer = FindObjectOfType<PlayerController> ();
countHealth = maxHealth;
whatToReset = FindObjectsOfType<ResetRespawn>();
if (PlayerPrefs.HasKey ("countingCoins")) {
countingCoins = PlayerPrefs.GetInt ("countingCoins");
coinText.text = "Coins: " + countingCoins;
}
if (PlayerPrefs.HasKey ("PlayerLives")) {
currentLives = PlayerPrefs.GetInt ("PlayerLives");
} else {
currentLives = startLives;
}
liveText.text = "Lives - " + currentLives;
}
At the moment my countCoins
adds up by ten and my currentLives
keeps adding lives itself.
GIF of current lives changing value when I start game
I just want to carry the current values to next scene.
Any idea how can I fix this or where my code is wrong?