High Score with Game Over Screen issue: PlayerPrefs

I have an endless game where the score increases based off of Time.fixedDeltaTime. I’m trying to store a high score in player preferences if it is higher than the earned score but it doesn’t seem to be sticking. Can someone point out what I’m doing wrong here? I’m storing scores in a HUDScript and presenting score and high score in game over script.

HUDScript:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HUDScript : MonoBehaviour {

	float playerScore = 0;
	public Text scoreText;

	void Start () {
		Screen.sleepTimeout = SleepTimeout.NeverSleep;
		Screen.orientation = ScreenOrientation.LandscapeLeft;
	}


	void Update () {
		playerScore += Time.fixedDeltaTime;
		scoreText.text = "Score: " + Mathf.Floor((playerScore * 100)).ToString();

	}

	public void IncreaseScore(int amount){
		playerScore += amount;
	}

	void OnDisable() {
		PlayerPrefs.SetInt ("Score", (int)(playerScore * 100));
		if (PlayerPrefs.GetInt("HighScore") <= (int)playerScore)
			PlayerPrefs.SetInt("HighScore", ((int)playerScore));

	}

}

GameOverScript:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameOverScript : MonoBehaviour {

	HUDScript hud;
	int score = 0;
	int highScore = 0;
	public Text scoreText;
	public Text highScoreText;


	// Use this for initialization
	void Start () {
		score = PlayerPrefs.GetInt ("Score");
		scoreText.text = "Score: " + score.ToString ();
		highScore = PlayerPrefs.GetInt ("Score");
		highScoreText.text = "High Score: " + highScore.ToString ();
	}
	
	void Update () {
		
	}
}

0
down vote
accept

I was able to resolve my issue by moving the high score checking logic to the GameOver script. I’m new to Unity and C# so this wasn’t obvious to me until after my third cup of coffee. Thanks and sorry for the ambiguity.

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HUDScript : MonoBehaviour {

    float playerScore = 0;
    public Text scoreText;


    void Start () {
    }

    void Update () {
        playerScore += Time.fixedDeltaTime;
        scoreText.text = "Score: " + Mathf.Round((playerScore * 100)).ToString();

    }


    public void IncreaseScore(int amount){
        playerScore += amount;
    }

    void OnDisable() {
        PlayerPrefs.SetFloat ("Score", Mathf.Round((playerScore * 100)));

    }

}

    using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameOverScript : MonoBehaviour {

    HUDScript hud;
    float score = 0;
    float highScore;
    public Text scoreText;
    public Text highScoreText;


    // Use this for initialization
    void Start () {
        score = PlayerPrefs.GetFloat ("Score");
        highScore = PlayerPrefs.GetFloat ("HighScore", 0);

        scoreText.text = "Score: " + score.ToString ();
        if (score > highScore) {
        highScoreText.text = "High Score: " + score.ToString ();
            PlayerPrefs.SetFloat("HighScore", score);
        } else {
            highScoreText.text = "High Score: " + highScore.ToString();
        }

    }

}