- Home /
Question by
jolyjokerz · Aug 23, 2013 at 06:44 PM ·
distancevectorcounterdistance check
variable++ error...
int sayac = 0;
void Start () {
car = GameObject.FindGameObjectWithTag("car");
AIcar = GameObject.FindGameObjectWithTag("AI");
}
void Update () {
cardis= Vector3.Distance (car.transform.position, waypoints[sayac].transform.position);
aidis = Vector3.Distance (AIcar.transform.position, waypoints[sayac].transform.position);
if(aidis < 1)
sayac++;
Debug.Log(sayac);
}
return value sayac = 0, sayac = 1, sayac = 1, sayac = 1, sayac = 1, first run working code but why does not continue ?
Comment
Answer by save · Aug 23, 2013 at 07:11 PM
It's because
if(aidis < 1)
The result is that sayac will only increment if it's below 1.
How else can I do? automatically closes in an other waypoint let pass through?
Your logic seems right on.
The problem is that the AIcar never comes close enough to waypoint #2.
Print out aidis and you will see that it never gets below 1 after the first waypoint.