finish line script

script need correcting for a racing game.

var laps : int;

 function OnTriggerEnter (racer : Collider) {
      if (racer.Controller.laps < 5) { 
           laps++;
      } 
      else if (racer.Controller.laps >=5) {
           winGame();
      }
 }

function winGame () {
      //do winning stuff here.
      Application.LoadLevel("2"); //another level for instance.
} 

Assets/startfinishline.js(4,21): BCE0019: ‘Controller’ is not a member of ‘UnityEngine.Collider’.
Assets/startfinishline.js(4,68): BCE0019: ‘Controller’ is not a member of ‘UnityEngine.Collider’.

Assuming Controller is a component attached to the racer’s game object you would have to have a GetComponent(“Controller”), or something similar, in there somewhere to get a reference to it before you could use it’s members.

The solution to the errors you’re getting is that the variable ‘racer’ is a Collider and there is no property called ‘Controller’ associated with colliders.

  if (racer.Controller.laps < 5) { 

This needs to be changed, but without more details, you’re not going to get much useful information.

I guess, like terdos said you want to access a component (script) that is called Controller. You should do something like that:

function OnTriggerEnter (racer : Collider) {
    var controller = GetComponent.<Controller>();
    if (controller.laps < 5) { 
        laps++;
    } 
    else if (controller.laps >=5) {
        winGame();
    }
}