Question by
JonKukula · Jan 17, 2017 at 08:44 PM ·
javascriptapplehighscoreshighscore
High Score Save iOS
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:
import System.IO;
static var CompareScore : int;
var fileName = "highscore.data";
var ScoreLoad : String;
var HighScoreDisplay : GameObject;
var line : String;
function Start () {
//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>().text = "Best: " + ScoreLoad;
CompareScore = int.Parse(ScoreLoad);
}
ScoreSave.js:
import System.IO;
var fileName = "highscore.data";
var ScoreAmount : int;
var HighScore : int;
function Start () {
HighScore = ScoreLoad.CompareScore;
ScoreAmount = Score.TheScore;
if (ScoreAmount >= HighScore) {
//var OurFile = File.CreateText(fileName);
// OurFile.WriteLine (ScoreAmount);
//OurFile.Close();
PlayerPrefs.SetInt("HighScore", ScoreAmount);
}
}
Score.js:
import UnityEngine.UI;
static var TheScore : int;
var ScoreDisplay : GameObject;
var EndScoreDisplay : GameObject;
function Start () {
//After 0 seconds "AddScore" starts. From then on it starts every 0.1 seconds.
TheScore = 0;
InvokeRepeating("AddScore", 0, 0.1);
}
function AddScore () {
TheScore += 0;
ScoreDisplay.GetComponent.<Text>().text = "Score: " + TheScore;
EndScoreDisplay.GetComponent.<Text>().text = "Score: " + TheScore;
}
Comment