Help for timer script...

Hello all :slight_smile:

Sorry in advance for my bad english, thank you google translation :slight_smile:

I am 3d modeler, and now I want to put my car in a 3D video game enthusiast …
I found the " Car Tutorial ", it is very complete and suitable for me, but I would like to add a function to count laps and timing …

I found this script on the Unity wiki: http://wiki.unity3d.com/index.php/Timer

I’m not a programmer and I would like a little help to improve it, it gives me the current time and the best time with a line between the trigger that counted the laps ( or a tutorial for example… ;))

Thank you in advance :slight_smile:


www.aego-prod.fr

Hében :slight_smile:

I looked at the script and was wondering what improvements your looking for? I’m a Js er, but for the most part the script just fades in and out the alpha of a guitext to display the timer.

For counting laps you may want to place a node/Empty at the front of the car so that the trigger reads the nose of the car and not the center transform. Make sure that each car has its own lap count var.

var cOneLapCount : int;
//--------------------------------------------------------------------------------------------------------------//
function OnTriggerEnter(col : Collider) {
    //------------//
    if(col.tag==carOneNode) {
      cOneLapCount ++;//Add one to the lapCount
      print("cOneLapCount = " + cOneLapCount);
      if(cOneLapCount>=3) {
        //End Race and declare carOne the winner code here - lol
      }
    }
    //------------//
}
//--------------------------------------------------------------------------------------------------------------//
//Untested But looks about right lol

In the same script you will need the variables and code blocks for each car (eg) cTwoLapCount

Thank you for your help Black Mantis :slight_smile: