Hello,
I recently had a class assignment to make a version of Apple Picker from the 2015 book “Introduction to Game Design, Prototyping, and Development” using the newest version of Unity.
Some things are not the same however and the high score bit was difficult to get going. I was able to get it working however. This was my fix.
In the “HighScore” script I used:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class HighScore : MonoBehaviour {
static public int score = 1000;
public Text gameText;
public GameObject highScore;
void Start() {
//if the ApplePickerHighScore already exists, read it
if (PlayerPrefs.HasKey ("ApplePickerHighScore")) {
score = PlayerPrefs.GetInt ("ApplePickerHighScore");
} else {
// assign the high score to ApplePickerHighScore
PlayerPrefs.SetInt ("ApplePickerHighScore", score);
}
gameText = highScore.GetComponent<Text> ();
}
void Update () {
gameText.text = "High School: "+score;
//update ApplePickerHighScore in PlayerPrefs if necessary
if (score > PlayerPrefs.GetInt ("ApplePickerHighScore")) {
PlayerPrefs.SetInt ("ApplePickerHighScore", score);
}
}
}
This is just one of many solutions. I only put this here because I haven’t seen anyone update the code for Apple Picker, or at least I had a hard time finding any updates. Hopefully this will help someone in the future going through it.