Hi!
I have a problem in my script. This is my script. The problem is that the best time doesn’t save.
static var currentScore : int = 0;
var timer : float = 0.00;
var bestTime : float;
function Start () {
}
function Update () {
if (currentScore == 20) {
if (bestTime > timer){
bestTime = timer;
var bestTimer = PlayerPrefs.GetFloat("bestTimer");
PlayerPrefs.SetFloat("bestTimer", bestTimer);
PlayerPrefs.Save();
}
}
}
function OnGUI ()
{
GUI.Box(new Rect(90, 10, 70, 20), "" + timer.ToString (""));
}
Timer script:
var timer : float = 0.00;
static var currentScore : int = 0;
function Update ()
{
timer += Time.deltaTime;
}
function OnGUI ()
{
GUI.Box(new Rect(10, 10, 70, 20), "" + timer.ToString (""));
}
Thank you. ![]()
Timer works great but it writes Best time : bestTime and when I reach score 20 it still writes Best time : bestTime. :/ Do you know why? Thank you for your help.
– josak46I had put a couple things in the wrong spot and didn't test it or anything. Just edited the original post, still didn't test it, but now it might work how you want lol ...
– Lo0NuhtiKAssets/skripte/timer.js(23,16): BCE0051: Operator '<' cannot be used with a left hand side of type 'float' and a right hand side of type 'Object'. I tried to do private var bestTime : float; but it doesn't work as I should. :) And in the game it writes Best time : Infinity.
– josak46It doesn't :(. I'm gonna' cry :). I don't know... I tried to change something with my noob knowledge but it doesn't save and bestTime is always Infinity. It doesn't change. I'd try to help you but i don't know. Thank you anyway.
– josak46Idk what's going on on your side, then, because I just went upstairs to double-check again and it works. Are you calling PlayerPrefs.DeleteAll() somewhere else in your game, or PlayerPrefs.DeleteKey("BestTime") ?? ..also.. are you ever adding to currentScore however you were doing it before???
– Lo0NuhtiK