Reset score to what the value was at the start of the level (unless you have touched a checkpoint)
So I need the players score to reset to its value at the start of the level unless the player has passed through a checkpoint. From that point it needs to reset to whatever the score was at the time of them touching the checkpoint.
So far my Checkpoint code is this:
void Start()
{
thePlayer = GameObject.FindGameObjectWithTag("Player");
hudController = thePlayer.GetComponent<hudController>();
gameMaster = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{ gameMaster.lastCheckpoint = transform.position;
PlayerPrefs.SetInt("Lives", hudController.playerLives);
PlayerPrefs.SetInt("Beer", hudController.beerCount);
PlayerPrefs.SetInt("Score", hudController.playerScore);
}
}
and within my hudController (manages the value changes and holds the player Lives, beerCount and score ints) I have this code.
void Start() { currentHealth = maxHealth; playerLives = PlayerPrefs.GetInt("Lives", playerLives); beerCount = PlayerPrefs.GetInt("Beer", beerCount); playerScore = PlayerPrefs.GetInt("Score", playerScore); }
private void OnDestroy()
{
PlayerPrefs.SetInt("Lives", playerLives);
PlayerPrefs.SetInt("Beer", beerCount);
PlayerPrefs.SetInt("Score", playerScore);
}
At a complete loss right now. Any help would be appreciated
Answer by Ak0rn · May 06, 2019 at 04:58 AM
Goddamn this was even worse than my previous blunder.
Remove the Beer and Score set Int on destroy.
We out here making rookie mistakes.
Your answer
Follow this Question
Related Questions
High-score Saving Issue 2 Answers
Game over high score playerprefs 0 Answers
Saving Highscore with PlayerPrefs not working 0 Answers
Unlock a level if score in the previous level is right 0 Answers