- Home /
OnTriggerEnter only working twice...
Hi again guys and girls... I have issues with the following script... if my player car hits the trigger, it changes the bool, then if it hits it again, it changes it back... this is great but it only does this once and will no longer detect the trigger... am I missing something here?
function OnTriggerEnter(other : Collider)
{
if(other == ValidLap.collider)
{
if(bValidLapIsTrue == true)
{
bValidLapIsTrue = false;
print("Valid Lap Status = " + (bValidLapIsTrue));
}
else if(bValidLapIsTrue == false)
{
bValidLapIsTrue = true;
print("Valid Lap Status = " + (bValidLapIsTrue));
}
}
}
For starters, you don't need the
else if(bValidLapIsTrue == false)
bit- just
else
will do, because there are only ever two possible values for a boolean.
But I don't think that's the problem, it's just a stylistic thing. Just the same as the fact that
bValidLapIsTrue == true
is the same as just
bValidLapIsTrue
they will both return the same value, but one of them requires a small calculation first.
Yeah, true... I also didn't need to repeat the print code... could have just put it out of the brackets. I'm not too experienced with coding but $$anonymous$$INDA know what I'm doing... just can't work out why this isn't working each time it's triggered...
Well, it's a good question, I'll give you that. I suspect that it's something outside of this code snippet that is interfering with it.
Yeah, it's really weird... the console isn't printing more than twice but the bool seems to be changing... the lap counter is working perfectly...
Try using Debug.Log ins$$anonymous$$d. $$anonymous$$aybe it's a bit more reliable than the 'print' shortcut?