I've tried many examples from the internet, but none of them works. it's been 3days i stuck with this problem. I want to create a simple Save System that stores the fastest Time of a player when completing a level.
----------
public TextMeshProUGUI bestText; // Text for Best Time
public TextMeshProUGUI currTimeText;
public bool isFinished = false; // Check if game has finished
float timer;
private void Start()
{
if (PlayerPrefs.HasKey("BestTime"))
{
bestText.text = PlayerPrefs.GetFloat("BestTime").ToString("f2");
}
}
private void Update()
{
currTimeText.text = timer.ToString("f2");
if (!isFinished)
{
timer += Time.deltaTime;
} else
{
Debug.Log(timer);
timer += 0;
if (timer < PlayerPrefs.GetFloat("BestTime", float.MaxValue))
{
PlayerPrefs.SetFloat("BestTime", timer);
bestText.text = timer.ToString("f2");
PlayerPrefs.Save();
}
}
}
↧