- Home /
Question by
Gusic · Jul 27, 2015 at 11:08 PM ·
c#2dhighscores
Highscore not working
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.
CODE
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreOnEnd : MonoBehaviour
{
public static ScoreOnEnd End;
public Text countText;
private int count;
public Text HighScore;
private int Highcount;
public GameObject Player;
void Start ()
{
End = this;
countText.gameObject.SetActive(false);
count = 0;
SetCountText ();
HighScore.gameObject.SetActive(false);
Highcount = 0;
SetHighScore ();
Highcount = PlayerPrefs.GetInt ("HighScore1", 0);
}
void update () {
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Coin") {
count = count + 1;
SetCountText ();
} else if (col.gameObject.tag == "Enemy") {
countText.gameObject.SetActive(true);
HighScore.gameObject.SetActive(true);
}
}
void SetCountText ()
{
countText.text = " " + count.ToString ();
}
void SetHighScore ()
{
HighScore.text = Highcount.ToString ();
}
public void CheckHighScore(){
if (count > Highcount) {
PlayerPrefs.SetInt("HighScore1", count);
}
}
}
Comment
Answer by Hexer · Jul 27, 2015 at 11:21 PM
HighScore.text = Highcount.ToString ();
put this in the Update I'm wondering if it changes when you reach a new highscore.
public void CheckHighScore()
I assume you call this from another script? What is the calling method for this function.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Enemy chasing the player ? 2 Answers