Hello guys,
I have a problem with incrementing. I’m a beginner at coding, but you will see.
If I Trigger the Function I get both the values 0 and 1 back for the variable "
checkpointCounter"
… what’s the problem?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CheckpointSystem : MonoBehaviour
{
public int checkpointNumber;
int checkpointCounter;
public Text lapsText;
int laps;
void Start()
{
laps = 0;
checkpointCounter = 0;
}
private void Update() {
Debug.Log(checkpointCounter);
}
void OnTriggerEnter2D(Collider2D carOverCheckpoint){
if(carOverCheckpoint.gameObject.name == "Car")
if(checkpointNumber == 1 && checkpointCounter == 0)
checkpointCounter++;
else if(checkpointNumber == 2 && checkpointCounter == 1)
checkpointCounter++;
else if(checkpointNumber == 3 && checkpointCounter == 2)
checkpointCounter++;
else if(checkpointNumber == 4 && checkpointCounter == 3)
checkpointCounter++;
else if (checkpointNumber == 5 && checkpointCounter == 4){
laps++;
lapsText.text = "Laps: " + laps;
checkpointCounter = 0;
}
}
}
Thanks for your help.