- Home /
How to Display high score using GUIText
Well, i'm pretty new with unity. I got a problem to display highscore. The score was display everytime enemy were shot. I want to display the highscore everytime the game end and be able to update everytime i got a new highscore. The score system using the GUI text. The example below.
Score:
Highscore:
To display the score, i'm using this script
using UnityEngine;
public class HealthScript : MonoBehaviour
{
public int hp = 1;
private GUIText scoreReference;
public bool isEnemy = true;
public void Damage(int damageCount)
{
hp -= damageCount;
if (hp <= 0)
{
// Dead!
Destroy(gameObject);
scoreReference.text = (int.Parse(scoreReference.text) + 1).ToString();
}
}
void Start()
{
scoreReference = GameObject.Find("Score").guiText;
}
i got some idea to retrieve the value of the score, but it won't display. Please help me.. Thanks
actually, this is script for enemy health, it's not a full code.. just show the code that related to question
hi thanks extremepower, but that's not the problem at all.. Look at this screenshot, the score just fine, but i need to display the highscore and update the score if you got a new highscore. The question is how to do it?
for setting highscore
if(Score>PlayerPrefs.GetInt ("HIGHSCORE_$$anonymous$$EY",0))
{
PlayerPrefs.SetInt ("HIGHSCORE_$$anonymous$$EY",Score);
}
for getting HighScore simply
HighScore = PlayerPrefs.GetInt ("HIGHSCORE_$$anonymous$$EY",0);