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