hello, i got a problem here. I'm developing shooting game. Then, i need to display the high score but it's doesn't shown
here my health script (attached to every enemy)
using UnityEngine;
public class HealthScript : MonoBehaviour
{
public static HealthScript instance;
public int hp = 1;
private GUIText scoreReference;
private GUIText highscoreReference;
private static int _highscore = -1;
public int highscore {
get { if (_highscore == -1)
_highscore = PlayerPrefs.GetInt("Highscore", 0);
return _highscore;
}
set {
if (value > _highscore) {
_highscore = value;
highscoreReference.text = _highscore.ToString();
PlayerPrefs.SetInt("Highscore", _highscore);
}
}
}
public bool isEnemy = true;
private static int points;
public void Damage(int damageCount) {
hp -= damageCount;
if (hp <= 0)
{
// Dead!
Destroy(gameObject);
points++;
scoreReference.text = points.ToString();
}
}
public void gameEnd() {
points = highscore;
points = 0;
}
void Start()
{
scoreReference = GameObject.Find("Score").guiText;
highscoreReference = GameObject.Find("HighScore").guiText;
scoreReference.text = points.ToString();
highscoreReference.text = highscore.ToString ();
instance = this;
}
then this is my player script where i put the game over method
void OnDestroy()
{
// Game Over.
// Add the script to the parent because the current game
// object is likely going to be destroyed immediately.
transform.parent.gameObject.AddComponent<GameOverScript> ();
HealthScript.instance.gameEnd ();
}