How to save highscore in every level??

I make a puzzle game, that have many level on it…at that level there is highscore, i used PlayerPrefs…the question is…how to save highscore in every level? because the high score appear same in every level…

here is the code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System;

public class Panel : MonoBehaviour {

public GameObject Canvas;
public GameObject MyScore;
public Text Score;
public Text highScoreText;
public Scene scene;

void Awake()
    Scene scene = SceneManager.GetActiveScene();

void Start()

    MyScore = Canvas.transform.Find("timer").gameObject;
    Score.text = MyScore.GetComponent<Text>().text;
   highScoreText.text = PlayerPrefs.GetInt("HighScore", 00).ToString();
   // highScoreText.text = PlayerPrefs.GetInt("HighScore" +, 00).ToString();
    // highScoreText.text = PlayerPrefs.GetInt("HighScore2" + SceneManager.GetSceneByName("level 1")).ToString();
    // highScoreText.text = PlayerPrefs.GetInt("HighScore3" + SceneManager.GetSceneByName("level 2")).ToString();
    // highScoreText.text = PlayerPrefs.GetInt("HighScore4" + SceneManager.GetSceneByName("level 3")).ToString();
    // highScoreText.text = PlayerPrefs.GetInt("HighScore5" + SceneManager.GetSceneByName("level 4")).ToString();
    // highScoreText.text = PlayerPrefs.GetInt("HighScore6" + SceneManager.GetSceneByName("level 5")).ToString();
    // MyText = transform.Find("timer").GetComponent<UnityEngine.UI.Text>();

void Update()
    int myNewScore = int.Parse(Score.text);
    Score.text = myNewScore.ToString();

    if (myNewScore > PlayerPrefs.GetInt("HighScore"))
        PlayerPrefs.SetInt("HighScore", myNewScore);
        highScoreText.text = myNewScore.ToString();

    /*if (myNewScore > PlayerPrefs.GetInt("HighScore2"))
        PlayerPrefs.SetInt("HighScore2", myNewScore);
        highScoreText.text = myNewScore.ToString();
    if (myNewScore > PlayerPrefs.GetInt("HighScore3"))
        PlayerPrefs.SetInt("HighScore3", myNewScore);
        highScoreText.text = myNewScore.ToString();


Hello there,

You probably shouldn’t do this in Update() to start.

But regarding your question, a PlayerPrefs key is unique, so when you get to level 2 you’ll be overriding your level 1 highscore.

To fix that you could add something to your key name, like "HighScore_" + level.ToString();.
Now assuming “level” is your level ID or name, you’ll have a unique key for each level.

I hope that helps!



Have a playerprefs int(high score) unique for each level and show and increase it accordingly.

better late than never what i did was:

[serialized] public int level;

 PlayerPrefs.SetFloat("Highscore" + level, MynewScore);

then input the level on gameobject so 1 for lvl 1 and so on for each scene.