Simple High Score Script Question

Hello,

I’m trying to put a very simple highscore script on my game, so that while you are playing it displays your current high score and updates itself when it passes your previous highscore. Thi is the code I currently have set up.

public class PlayerController : MonoBehaviour
{

	public GUIText HighScoreText;
	public int HighScore;
void StoreHighscore(int newHighscore)
	{
		int oldHighscore = PlayerPrefs.GetInt("highscore", 0);    
		if (newHighscore > oldHighscore) 
		{
			PlayerPrefs.SetInt ("highscore", newHighscore);
		}
		PlayerPrefs.Save();
	}

Can you help me to see where I am at error. I don’t get any script error, but it doesn’t function.

There does not seem to be anything wrong with StoreHighscore. However since it is never called within the class (and as a private member cannot be called from outside the class) it “never functions”. To call StoreHighscore you could add the line

StoreHighscore(Highscore);

at line 77 so the high score is stored every time the player dies.

public class PlayerController : MonoBehaviour
{

     public GUIText HighScoreText;
     public int HighScore;
 void StoreHighscore(int newHighscore)
     {
         int oldHighscore = PlayerPrefs.GetInt("highscore", 0);    
         if (newHighscore > oldHighscore) 
         {
              HighScoreText.text = oldHighscore;  // add this line
             PlayerPrefs.SetInt ("highscore", newHighscore);
         }
         PlayerPrefs.Save();
     }