Where is the bug? Please Help

So will make a Highscore, but it don´t works.

Can you complete the code for me?

I have no idea what i will make.

Thanks for every help :slight_smile:


var target : Transform;
private var myTransform : Transform;
var currentDistance : String = “”;

var score : GUIText;
var highScore : GUIText;

var bestScore : float = 0;

function Start () {
myTransform = transform;

if (PlayerPrefs.HasKey(“Hightscoreab”)){
bestScore = PlayerPrefs.GetFloat(“Hightscoreab”);

}

}

function Update () {
var distance = (target.position - myTransform.position).magnitude;
currentDistance = distance.ToString(“F0”);
score.text = "Punkte: " + currentDistance;

if (bestScore <= score) { /////here is a bug say unity

PlayerPrefs.SetFloat(“Hightscoreab”, score)(); ////here is a bug say unity
}

}

////maybe are more bugs, thank you for every help

You are checking and saving in the prefs “score” (that is a GUIText) instead of “distance” that is the float you want to check and save.

PlayerPrefs.SetFloat("Hightscoreab", score);

Like SkaredCreations say you comparing the wrong variable and your playerprefs saving function is wrong it should not had an additional () at the back.

score is a GUIText - not a value, it’s a whole object.

PlayerPrefs.SetFloat(“Hightscoreab”, score.text);

However, that’s still a string, so even if it’s just a number, it’s actually still a string, not a float.

Try (untested)…
PlayerPrefs.SetFloat(“Hightscoreab”, float.Parse( score.text ) );