title: Unity-How Do I make a High Score?
body: <p>I'm making a survival shooter game, and I'm trying to make it so when I kill an enemy it adds points to my score. The score is added to the high score and it is saved after each play. I have the script to add score, but I don't think I'm doing high score right. Could someone help me with this please?</p>
  
  <pre><code>public class ScoreManager : MonoBehaviour
  {
      public static int score;
      public static int highScore;
  
      Text scoreText;
      Text highScoreText;
  
      void Awake ()
      {
          scoreText = GetComponent &lt;Text&gt; ();
          highScoreText = GetComponent&lt;Text&gt;();
          score = 0;
          highScore = 0;
  
          highScoreText.text = PlayerPrefs.GetInt("High Score", 0).ToString();
      }
      void Update ()
      {
          scoreText.text = "Score: " + score;
          highScoreText.text = "High Score: " + highScore;
          if(score&gt;PlayerPrefs.GetInt("High Score", 0))
          {
              PlayerPrefs.SetInt("High Score", score);
              highScoreText.text = score.ToString();
          }
      }
  }  
  </code></pre>
  
  <p>Here's the enemy health script for adding to score when enemy dies.
  It's in the enemySinking function.</p>
  
  <pre><code>public class EnemyHealth : MonoBehaviour
  {
      public int startingHealth = 100;
      public int currentHealth;
      public float sinkSpeed = 2.5f;
      public int scoreValue = 10;
      public AudioClip deathClip;
  
  
      Animator anim;
      AudioSource enemyAudio;
      ParticleSystem hitParticles;
      CapsuleCollider capsuleCollider;
      bool isDead;
      bool isSinking;
  
  
      void Awake ()
      {
          anim = GetComponent &lt;Animator&gt; ();
          enemyAudio = GetComponent &lt;AudioSource&gt; ();
          hitParticles = GetComponentInChildren &lt;ParticleSystem&gt; ();
          capsuleCollider = GetComponent &lt;CapsuleCollider&gt; ();
  
          currentHealth = startingHealth;
      }
  
  
      void Update ()
      {
          if(isSinking)
          {
              transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);
          }
      }
  
  
      public void TakeDamage (int amount, Vector3 hitPoint)
      {
          if(isDead)
              return;
  
          enemyAudio.Play ();
  
          currentHealth -= amount;
  
          hitParticles.transform.position = hitPoint;
          hitParticles.Play();
  
          if(currentHealth &lt;= 0)
          {
              Death ();
          }
      }
  
  
      void Death ()
      {
          isDead = true;
  
          capsuleCollider.isTrigger = true;
  
          anim.SetTrigger ("Dead");
  
          enemyAudio.clip = deathClip;
          enemyAudio.Play ();
      }
  
  
      public void StartSinking ()
      {
          GetComponent &lt;UnityEngine.AI.NavMeshAgent&gt; ().enabled = false;
          GetComponent &lt;Rigidbody&gt; ().isKinematic = true;
          isSinking = true;
          ScoreManager.score += scoreValue;
          Destroy (gameObject, 2f);
      }
  }  
  </code></pre>
  
  <p>But I am facing two problems:</p>
  
  <ol>
  <li>When I restart the game, the high score text replace the score text</li>
  <li>When I kill enemies the score text is not updated</li>
  </ol>