Lap Timer Help

I’ve found some unity3d code online for a lap timer. I added the script to a collider with a trigger. The timer starts immediately when the scene is run, which is good but how do i make it so when you hit the box collider the time goes back to zero(resets) and counts up again? Its C# so i’m a little lost, just getting used to the javascript.

    using UnityEngine;
    using System.Collections;
     
    public class LapTimer : MonoBehaviour {
     
    private float startTime;
    private float ellapsedTime;
     
    void TimerStart()
    {
    startTime = Time.time;
    }
    void Update()
    {
    ellapsedTime = Time.time - startTime;
    }
	 void OnGUI(){
GUI.TextArea(new Rect(10,30,60,20), (ellapsedTime.ToString()));
}
}

with javascript it would have been something like below, but how do you do it in C#?

function OnTriggerEnter (other : Collider) {
//something in here involvng getting the timer to start over again
}

Also the timer show like 10 digits after the decimal.How do I make it only show one decimal place (10.4) instead of(10.44645646)
This would be mathf.round or something in java right? but what about C#, is there a rounding code?

on the right hand side, just above the code sample boxes is a toggle for which language it’s showing. Looks like it defaults to javascript but you can view the samples as c# and Boo.

Turning this on it’s head, if you’re used to javascript more than c# you can use the most of the code you’ve posted above in a javascript if you change the syntax a little…

(unchecked so might have typos, but you get the idea)

private var startTime		: float;
private var ellapsedTime	: float;

    function Start() {
    startTime = Time.time;
    }

    function Update() {
    ellapsedTime = Time.time - startTime;
    }

     function OnGUI() {
		GUI.TextArea(new Rect(10,30,60,20), (ellapsedTime.ToString()));
	}

edit: oh and resetting the timer is the same code line as in the timerstart/start function.

Thanks alot leftyrighty! I find javascript so much easier than C#.