So I want to make hill climb wanna be game but have an issue with saving bestTime each level, the point is I want to save the best time for each level to playerprefs also save it on text value in main menu like the image.
here my timer script :
public void TimerSystemOn()
{
if (timerIsRunning)
{
if (timeRemaining > 0)
{
timeRemaining -= Time.deltaTime;
DisplayTime(timeRemaining);
}
else
{
if (timeRemaining <= 0)
{
Debug.Log("Time has run out!");
timeRemaining = 0;
timerIsRunning = false;
if (!timerIsRunning)
{
TimeOut();
}
}
}
}
if (!timerIsRunning)
{
ReachFinishLine();
DisplayTime(timeRemaining);
}
}
void DisplayTime(float timeToDisplay)
{
timeToDisplay += 1;
float minutes = Mathf.FloorToInt(timeToDisplay / 60);
float seconds = Mathf.FloorToInt(timeToDisplay % 60);
PlayerPrefs.SetFloat("Minutes", minutes);
PlayerPrefs.SetFloat("Seconds", seconds);
timeText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
float highscoreMins = PlayerPrefs.GetFloat("Minutes");
float highscoreSec = PlayerPrefs.GetFloat("Seconds");
if (minutes > highscoreMins || seconds > highscoreSec)
{
PlayerPrefs.SetFloat("Minutes", minutes);
PlayerPrefs.SetFloat("Seconds", seconds);
}
Debug.Log("HighscoreSec : " + highscoreSec);
}
that's my current script to save the bestTime. and this script call on the game, when died the timer value or time remaining = 0 and when the car reached the destiny timer will be stopped but the value saved to best time
I confused here about saving that value and save it on each level
