- Home /
Question by
BenIV · May 23, 2017 at 02:49 PM ·
javascriptplayerprefsconversionhighscoressystem.io
How would I transfer these into PlayerPrefs?
So right now the high score is being saved to a file thats easily editable by the player. That isnt really secure for a high score. How do I make it so that insted of the OurFile stuff, it just saves the value and then posts it? Im a playerprefs noob and anything helps, thanks.
(JAVA) Score load: import System.IO;
var fileName = "hs.data";
var ScoreLoad : String;
var HighScoreDisplay : GameObject;
var line : String;
static var CompareScore : int;
function Start(){
var sr : StreamReader = new StreamReader(fileName);
line = sr.ReadLine();
while (line != null){
ScoreLoad = line;
line = sr.ReadLine();
}
sr.Close();
HighScoreDisplay.GetComponent.<Text>().text = "" + ScoreLoad;
CompareScore = int.Parse(ScoreLoad);
}
and Score Save (java): import System.IO;
var fileName = "hs.data";
var ScoreAmount : int;
var HighScore : int;
function Start (){
HighScore = ScoreLoad.CompareScore;
ScoreAmount = GlobalScore.CurrentScore;
if (ScoreAmount >= HighScore){
var OurFile = File.CreateText(fileName);
OurFile.WriteLine (ScoreAmount);
OurFile.Close();
}
}
Comment
Well PlayerPrefs is very simple, here's an example.
if (ScoreAmount > PlayerPrefs.GetInt("Highscore"))
{
PlayerPrefs.SetInt("Highscore", ScoreAmount);
}