Hi, so I am trying to get the high score to work on my iOS device. I currently have the app on my phone using TestFlight but I need help with the high score as it is just blank. I am not the best scripter and I am using JavaScript. Below is my script…
Please help me get this to work on my APPLE DEVICE.
ScoreLoad.js:
importSystem.IO;
staticvarCompareScore:int;
var fileName =“highscore.data”;
varScoreLoad:String;
varHighScoreDisplay:GameObject;
var line :String;
functionStart(){
//sr is short for streamreader
//var sr : StreamReader = new StreamReader(fileName);
//line = sr.ReadLine();
// while (line != null) {
// ScoreLoad = line;
// line = sr.ReadLine();
// } //sr.Close();
ScoreLoad=PlayerPrefs.GetString(“HighScore”);
HighScoreDisplay.GetComponent.().text ="Best: "+ScoreLoad;
CompareScore=int.Parse(ScoreLoad);
Wow, that’s hard to read! Even more so than JS normally is. Please use code tags to make it easier.
I can see that you’re using PlayerPrefs, which is the right approach. I can’t guess what you’re intending with most of the code, though — why are you calling AddScore, to add zero points to your score every 10th of a second?
Note that you don’t have to test this on your device, which is a very slow process, I know! PlayerPrefs works exactly the same in the editor as it does on the device, so you can test it just by hitting Run within Unity. Also, throw in lots of Debug.Log calls to check your assumptions about what your code is doing.
I think you are missing the use of PlayerPrefs.Save() to write all down to disk.
In any case, I do recommends to use this instead of PlayerPrefs.
Best regards.