Hi, I new with unity and I want to ask about high score…
I already search everything but still not working also Im very new with javascript.
I want create simple leaderboard but score wont save and its all 0, i dont know how to fix this.
this is my skor.js
static var score : int;
var guiScore : GUIText;
static var teks = false;
static var reset = false; // fungsi reset
static var HScore = false;
function Start()
{
//Skor dari stage lama dibawa ke stage baru
guiScore.text = "Score: " + score;
}
function LateUpdate()
{
if(teks)
{
guiScore.text = "Score: " + score;
teks = false;
HScore = true;
}
if(reset) // mereset score ulang
{
guiScore.text = "Score: 0";
score = 0;
reset = false;
}
if(HScore) //my score script
{
if(score > PlayerPrefs.GetInt("wormScore"))
{
PlayerPrefs.SetInt("wormScore", score);
}
HScore = false;
}
}
and this is coba.js script
var complete = true;
static function AddScore(score : int)
{
var newScore : int;
var oldScore : int;
newScore = score;
for(i=1;i<=5;i++)
{
if(PlayerPrefs.HasKey(i+"wormScore"))
{
if(PlayerPrefs.GetInt(i+"wormScore")<newScore)
{
// new score is higher than the stored score
oldScore = PlayerPrefs.GetInt(i+"wormScore");
PlayerPrefs.SetInt(i+"wormScore",newScore);
newScore = oldScore;
}
}
else
{
PlayerPrefs.SetInt(i+"wormScore",newScore);
newScore = 0;
}
}
}
function OnGUI()
{
if(complete)
{
for(i=1;i<=5;i++)
{
GUI.Box(new Rect(100, 75*i, 150, 50), "Pos "+i+". "+PlayerPrefs.GetInt("wormScore"+i));
}
}
}
I dont know why all position score still 0. any help please?