your script looks good… except for line 43 when you compare “transform.position == waypoints [waypointIndex].transform.position”.
when you are moving things along, vector3’s are float values and between frames might not exactly equal the waypoint position or “skip” over it. this code will work if you either round off the position values for comparison or subtract the coordinates to see if the diffence is within a tollerance.
when you compare if the postion equals the way point try a function like this for comparison instead of using “==”
public bool IsCloseEnouphTo(Vector3 a, Vector3 b ){
float tollerance = .5f;//<-adjust tollerence here
float dif = 0; bool ret = false;
if (Mathf.Abs (a.x - b.x) > tollerance) {
ret = false;} else {if (Mathf.Abs (a.y - b.y) > tollerance) {ret = false;}
else{if (Mathf.Abs (a.z - b.z) > tollerance) {
ret = false;}}}return ret;}
checking unity’s Vector3.distance would work too but the above code would give the same result and avoid the heavier cpu usage of the sqaure roots calculations in the actual distance formula.