I don’t know how does your code look like but I’ll give you a code which displays the time in the format that you’d like to display:
First of all you need 4 variables for this. A variable which represents time, one for milliseconds, one for seconds and one for the minutes. Plus you need another variable to only add up time if you need to.
private float millisecond, time;
private int second, minute;
private bool timerIsOn = true;
In your Update method, the magic happens. First you store Time.deltaTime in your time variable, which is basically the time passed between frames, since your game doesn’t always run at 60fps or so. You add up this number, which is around 0.016 per frame or so, as many times as you need, we’re gonna use a second here for our measurement. Then it’s plain as it is, if a second has passed, you increment your second variable by one, when 60 seconds have passed you increment your minute variable by one etc… For the milliseconds I used our time variable multipled by 100 to get the correct value.
void Update () {
time += Time.deltaTime;
if (timerIsOn) {
//set second
//set second
if (time > 1.0f) {
second++;
time = 0.0f;
//set the minute
if (second > 59) {
second = 0;
minute++;
}
}
//set millisecond
millisecond = Mathf.Floor(time * 100.0f);
}
}
Then for the displaying. I wrote a method which makes the display nicer, which here means that you don’t get any result like having none formatted values like: ** 1: 1: 5 ** instead you get ** 01:01:05**. If you want I can explain this to you in comment.
The method looks like this:
string zero(int _time){
if (_time < 10)
return "0";
else
return "";
}
Last but not least you have to display these variable through your OnGUI() method
void OnGUI(){
//Draw Time
GUI.Label (new Rect(Screen.width * 0.025f, Screen.height - Screen.height * 0.2f, 30, 50), zero (minute)+minute.ToString() +":");
GUI.Label (new Rect(Screen.width * 0.025f + 30, Screen.height - Screen.height * 0.2f, 30, 50), zero (second)+second.ToString() +":");
GUI.Label (new Rect(Screen.width * 0.025f + 60, Screen.height - Screen.height * 0.2f, 25, 50), zero ((int)millisecond)+millisecond.ToString());
}
To stop the timer when you get 7 objects I’d suggest you to use a code which when your variable which counts the gathered objects turns to 7, basically turn timerIsOn variable to false.