A more sophisticated approach would be to use coroutines
Coroutines lets you create pauses in your code executions and are more flexible than Update().
You can start a coroutine when you collect a cube and than stop it when you collect another one.
About your leaderboard, while I am not a big fan of the following solution, it may be the simplest one.
Create a UI with your leaderboard and Texts as children of the leader board.
Attach the script below to a new empty gameObject in your scene
Drag & drop the Texts representing the best scores. Make sure to add them in the correct order (first one = best score ; last one = worst score). Don’t forget to add the leaderboard itself in the Leaderboard field.
In the Time script, declare a public variable called HighScoresManager and call HighScoresManager.AddScore( Time.time - startTime ) ; and HighScoresManager.ShowLeaderBoard() in the finish function.
using UnityEngine ;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
public class HighScoresManager : MonoBehaviour
{
public GameObject Leaderboard;
public Text HighScoresTexts;
private void Start()
{
Leaderboard.SetActive(false);
}
public void ShowLeaderBoard( )
{
Leaderboard.SetActive(true);
}
public void AddScore( float score )
{
// Retrieve the highscores
string serializedHighScores = PlayerPrefs.GetString("highscores");
List<string> highScores = new List<string>( serializedHighScores.Split( new char[]{'-'}, StringSplitOptions.RemoveEmptyEntries) );
// Add new score
highScores.Add( score.ToString("f4") ) ;
// Sort the scores in the descending order
highScores.Sort( (s1, s2) => float.Parse( s2 ).CompareTo( float.Parse( s1 ) ) ) ;
// Remove all the lowest scores
if( highScores.Count > HighScoresTexts.Length )
highScores.RemoveRange( HighScoresTexts.Length, highScores.Count - HighScoresTexts.Length);
for( int i = 0 ; i < HighScoresTexts.Length && i < highScores.Count ; ++i )
HighScoresTexts_.text = highScores*;*_