- Home /
Player Prefs not saving
I Am a student and learning so be genial with your responses
I have a wee problem I have a score and a total score made, when I load into a fresh scene the score resets which is What I Want but it also resets the total score. I would like to keep the total score value on all scenes, it displays this total score at the end of each level ... it's not a high score its more of a total score over all 3 levels. So if you get 5 points in level 1 the total score will be 5 but in level 2 you get a score of 2, the total score at the end of the level should display 7, etc.
I Am using playerprefs but it seems like not saving and loading on to the next scene. I Am defo missing something but I just can't see it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player1Score : MonoBehaviour
{
public static Player1Score instance;
public int score, highScore;
public Text ScorePlayer1Text, Player1HighScoreText;
public void Awake()
{
instance = this;
}
public void AddScore()
{
score++;
ScorePlayer1Text.text = score.ToString();
PlayerPrefs.SetInt("TotalScore", highScore);
UpdateHighScore();
}
public void UpdateHighScore()
{
highScore = PlayerPrefs.GetInt("TotalScore");
Player1HighScoreText.text = highScore.ToString();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612234057im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add score after destroying object in unity 2D? 1 Answer
How to give star(reward) only during the first time the mission is completed? 2 Answers
how to make high scores using playerprefs 2 Answers
Detailed Help on using PlayerPrefs? 1 Answer
Im Doing HighScore System To My Game And There Is Something Wrong In My Scripts 0 Answers