Ideas on creating a timer that stops when the goal has been reached?

Hi there!
I’m fairly new to coding in C# (not new to using unity though) and am curious as to how I would do this.

What I’m looking for is a timer that starts at 0:00 and begins counting up once the scene is loaded.
I’d like for it to count up and then stop once the ‘goal’ or ‘objective’ is completed, and be able to write the total time to another variable, like a high score board.

I’ve been looking around, and so far I think I should be using a Coroutine to make sure it’s counting every second:
IEnumerator countdown()
while (time > 0)
yield return new WaitForSeconds(1);

			timer.text = time.ToString();
			time += 1;

I’m using a public integer to assign the GUIText, and have it counting up in seconds, but not rolling over every minute. I also have no idea how to stop it once the end goal is reached, or to print the time/score to a scoreboard.

Any input on this would be greatly appreciated! Thanks a bunch!

Take a look at the Penelope tutorial.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class DisplayTime : MonoBehaviour {

    int timeVar;
    bool activateTimer;
    public bool goalCompleted;//set to true when goal is completed

    public Text displayTime;//assign in editor
	void Start () {
        activateTimer = true;
        goalCompleted = false;
	void Update () {
        if (activateTimer && !goalCompleted)
            timeVar = (int)Time.timeSinceLevelLoad; //(int) for single digit time. 
            displayTime.text = timeVar.ToString();