Using Playerprefs???

Ok. I know i’m meant to use playerprefs but i keep getting errors i want to save my high score so it displays on the main menu when you return to it and every tome you load the game up how would i do this?

The attached is what ive got that gets the score every time i go through the checkpoint any help would be really appreciated :slight_smile: Thanks.

Your problem maybe line 15 Destroy(gameObject)

If you want to destroy other object you have to use Destroy(collision.gameObject)

This is when reading:

if(PlayerPrefs.HasKey("score")){
	myScore = PlayerPrefs.GetInt("score");
}else{
	myScore = 0;
}

This is for writing:

if(PlayerPrefs.HasKey("score")){
	PlayerPrefs.SetInt("score", Mathf.Max(myScore, PlayerPrefs.GetInt("score"));
}else{
	PlayerPrefs.SetInt("score", myScore);
}

Good luck :slight_smile:

Try changing this line:

if(collision.gameObject.tag == "walls";

With this one:

if (collision.CompareTag ("walls")) {

If you get an error add gameObject to it:

if (collision.gameObject.CompareTag ("walls")) {

Please let met know if this fixed your issue!

You have on trigger enter? You not want OnCollisionEnter? Especially if your object is tagged.