I would like to compare two lap time and save the best record and display it on screen.
The best way is take the time foreach lap and after compare with the previous one?
public class CompareTime : MonoBehaviour
{
private float timer;
private float bestTime;
private bool lapComplete; // set to true at the end of each lap, according to game logic - should be public if changed from other script
private string niceTime;
public Text score;
private void Update()
{
timer += Time.deltaTime;
if (lapComplete) //only need to compare when a lap completes
{
if (timer < bestTime)
{
//Found new best time
bestTime = timer; //store new best time
float minutes = Mathf.Floor(bestTime / 60);
float seconds = Mathf.RoundToInt(bestTime % 60);
niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
score.text = niceTime.ToString();
timer = 0; // reset in order to measure time of next lap
lapComplete = false; //reset
}
}
}
}