Hi there,
I am having a little bit of trouble with sending the distance that my character has reached into my highscore.
I am using Player Prefs to save the highscore.
Here is my script for my DistanceCounter which is attached to my guiText.
var myTransform : Transform;
var origPos : Vector3;
var currentPos : Vector3;
var distance : float = 0;
static var distanceCount : int;
function Start()
{
origPos=myTransform.position;
currentPos=myTransform.position;
}
function Update ()
{
currentPos=myTransform.position;
Debug.Log((currentPos-origPos).magnitude);
distance += transform.position.x;
guiText.text = "Distance: " + myTransform.position.x.ToString("f2");
{
if (distance > PlayerPrefs.GetInt("score"))
{
PlayerPrefs.GetInt("score");
PlayerPrefs.SetInt("score",distance);
}
}
}
Here is my Highscore script which is attached to another guiText.
function OnGUI () {
guiText.text = "Highscore : " + PlayerPrefs.GetInt("score");
}
My high score will count up in seconds and save it perfectly with PlayerPrefs.
Can anyone help me so when my character reaches a certain distance it will display that in the high score? or point me in the right direction?
PS: Using Javascript
Thank you