Quick question.

Hello peeps,
quick question, I am trying to increment my lap counter plus one when I enter a trigger but it increments my lap by three for some reason,

 if (col.gameObject == triggerCounter)
        {
         laps++
        }

Could someone give me some insight on why this is happening?

Thanks

Well for one you are missing a semi-colon at the end of laps++

Other than that, there is too little code to be sure what is wrong.

Thanks for the reply, my bad I have one for the actual code, but here is the issue. I hit the trigger that is keep up with the laps but when I enter the trigger instead of it incrementing just the one lap it does 4 laps.

So say for instance my code goes:

void Update()
{
guitext.text = lapsCounted +" /3 laps"
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject == triggerCounter)
        {
           lapsCounted++;
        }
}

That is the whole code so I am trying to figure out why it increments like +3 or more when you enter the trigger?

The problem will probably be somewhere in your OnTriggerEnter code. You should post the rest of it so we can see what’s actually happening.

Why would the ontrigger function increment it +3 everything that I have seen suggests that it should do it only +1.
That is everything in the on trigger function.

It is only incrementing it by one, which means you’re colliding/calling the function 3 times.

EDIT: You’re missing another semicolon. Are you sure you’re showing us the whole function?

You’re entering the collider multiple times. Usually games have checkpoints systems specifically so they can ignore this exact issue -

if ( collided ) {
  if ( checkpoints == numCheckpoints ) {
    laps ++;
    checkpoints == 0;
  }
}

Ok I see the missed semicolon, I never thought that I was entering the trigger multiple times but that is how it is seemingly using it, how does this function work then, shouldn’t be that when you normally pass through the trigger it detects that you are in and out depending on your code instead of saying that this object in broken into bits and we are counting every bit of the object if that makes sense?

@Loius, that worked, WOW!!! Thanks everyone.