Hi! i have gone through different examples but i couldn't understand that much.. i really need help, In my game i want to save and compare current score and high score. if our current score is greater than high score then show our new high score and start comparing with new current score... here is my script in which i have current score and i have tried to applied playerprefs but couldn't work well .. kindly alter this code i will much glade.. at the end of the code i am displaying the current score .. if it is possible to show high score here kindly help....
#pragma strict
private var startTime:int;
// var labelPosition : Rect;
var labelText : String;
var labelStyle : GUIStyle;
var score : int;
var highScore: int=0;
var realTimeStart: int;
static var timer:boolean ;
function Start(){
startTime= Time.time;
timer=true;
}
function Update()
{
if (timer)
{
realTimeStart=(Time.time-startTime)*10;
PlayerPrefs.SetInt("realTimeStart",realTimeStart);
var GetScore:int= PlayerPrefs.GetInt("realTimeStart");
////////for high score
if(highScore>realTimeStart)
{
highScore=highScore;
PlayerPrefs.SetInt("HighScore",highScore);
var GetHS: int = PlayerPrefs.GetInt("HighScore");
print("High score" +GetHS);
//PlayerPrefs.GetInt("actualscore",highScore);
}
else
{
highScore=realTimeStart;
PlayerPrefs.SetInt("NewHighScore",highScore);
var GetNHS: int = PlayerPrefs.GetInt("NewHighScore");
// print("New High score" +GetNHS);
}
////// PlayerPrefs.SetInt("HighScore",realTimeStart);
labelText = realTimeStart.ToString();
PlayerPrefs.SetString("TimeScore",labelText);
}
}
function OnGUI()
{
GUI.Label(Rect (Screen.width-125, 30, 130, 25), labelText, labelStyle);
}
↧