Stop watch for 100 meter dash

Hey, a part of my game is a 100 meter dash and I need a stop watch for this part. The time should start counting when the player collides with the startline object and stop when the player hits the finishing line collider. In the Questionarea I’ve found the following code. It is counting, but only in the inspector. It does’nt stop atm. Any ideas how I can manage it? Greetings.

var Timer : float = 0;
var IncreaseTime : boolean = true;
var Start : GameObject;
var Ziel : GameObject;

 function Update () {
 
   if(IncreaseTime == true)
   {
   Timer += Time.deltaTime;
   }
 }
 
 function OnCollisionEnter (Col : Collision) {
 
   if(Col.gameObject.name == "finishingline_cube")
   {
   Time.timeScale = 0;
   }
 }

A few things…
So, do you know if the “OnCollisionEnter” function is being called? You can throw a debug.log(“Test”); statement into the “OnCollisionEnter” code to see if it is being called. The word “Test” should appear in the console if it is being called.
If not, that is your problem. For some reason, it’s not colliding. If it is being called, that’s great, then you can put the same debug code into the if statement and check if your if statement is working.

Also, you have the variable “IncreaseTime”, and you are using it in an if statement in the update function, yet you are not changing that value in your collision function. Change the

Time.timeScale = 0;

code to

IncreaseTime = false;