I have a score and high score script that doesn’t seem to be working there are no errors but the high score doesn’t update when the player dies.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class OnGui2D : MonoBehaviour {
public static OnGui2D OG2D;
public static int score;
int highScore;
Text scoreText;
Text highText;
// Use this for initialization
void Start () {
OG2D = this;
score = 0;
highScore = PlayerPrefs.GetInt ("HighScore1", 0);
scoreText = GameObject.Find ("ScoreText").GetComponent<Text> ();
highText = GameObject.Find ("HighText").GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
scoreText.text = ("" + (score + 0));
highText.text = ("" + highScore);
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Coin") {
score = score + 1;
} else if (col.gameObject.tag == "Enemy") {
OnGui2D.OG2D.CheckHighScore();
}
}
public void CheckHighScore(){
if ((score + 0) > highScore) {
Debug.Log ("Saving highscore");
PlayerPrefs.GetInt ("HighScore1", (score + 0));
}
}
}