Dear all,
I have been encountering a very irritating problem when creating my first app. I am trying to use the playerpref to save my score, but when it restarts, the highscore is reset to 0. I am an absolute beginner, so please treat me like a dunce. Ill paste the 2 scripts I have for scoring a point on trigger, and the other is the general score system.
I have tried this on my phone, and whenever I score a point and update the score, the highscore is 0.
Many thanks for the help
from fatmanspineapple
For the score point
using UnityEngine;
using System.Collections;
public class ScorePoint : MonoBehaviour {
void OnTriggerEnter2D(Collider2D collider){
if(collider.tag == "Player"){
ScoreSystem.AddPoint();
gameObject.SetActive(false);
}
}
}
For the score system
using UnityEngine;
using System.Collections;
public class ScoreSystem : MonoBehaviour {
static int score = 0;
static int highScore = 0;
static ScoreSystem instance;
static public void AddPoint(){
score++;
if (score > highScore) {
highScore = score;
}
}
void Start() {
PlayerPrefs.GetInt("highScore", 0);
}
void OnDestroy(){
PlayerPrefs.SetInt ("highScore", highScore);
score = 0;
}
void Update () {
guiText.text = "S:" + score + "
HS:" + highScore;
}
}