Adding a value after a trigger on

I am making a race car and I just want to add a value on my variable “Lap” once the car triggered a gameobject which act as my finish line

Simply i just want to do this

var lap = 0;

function OnTriggerEnter(other :
Collider) { if(other.gameObject.tag ==
“Player”) { lap +1; } }

then afterward i want to use the said value (lap) to show on my GUI and if the value is equals to 3 show a “Complete Race” text on my GUI

I used

var lapCounter : GameObject;

function OnGUI () { var curLap =
GUI.Label (Rect
(Screen.width-100,50,120,20), “Lap:”


var playerlap = 1; private var
guiEnable = false;

function OnGUI() { if (guiEnable) {
GUI.Label (Rect
COMPLETE”); } } function Update () {
if (playerlap == 3) { guiEnable =
true; } }

I don’t know what seems to be the problem…

I would approach this by having the lap counter variable in the main script, and have the lap counter trigger set it.

On your trigger you could have:

var myGameManager : GameManager;
function OnTriggerEnter(other : Collider) {
	if (other.gameObject.tag == "Player") {
		myGameManager.lap +1;

(Hate this lack of code formatting…pasted it:)

Then I would populate that slot in the inspector by grabbing your GameManager Object with the GameManager script on it and dragging it into the slot on the trigger.

This way the GameManager script do all of the manipulation and heavy lifting with a local value. With:

var lap : int; 

… in your main GameManager, having Update () and OnGUI() doing the work should be seamless.