void Update() { if (!isBlocked) { curSpeed = speed * Time.deltaTime; // Unify the speed. targetPoint = path.GetPoint(curPathIndex); // If reach the radius within the path then move to next point in the path. if (Vector3.Distance(transform.position, targetPoint) < path.Radius) { // Don't move the unit if the path is completed. if (curPathIndex < (pathLength - 1)) { curPathIndex++; } else if (isLooping) { curPathIndex = 0; } else { return; } } // Move the unit until the end point is reached in the path. if (curPathIndex >= pathLength) { return; } // Calculate the next Velocity towards the path. if ((curPathIndex >= (pathLength - 1)) && !isLooping) { velocity += Steer(targetPoint, true); } else { velocity += Steer(targetPoint); } transform.position += velocity; // Move the unit according to the velocity. transform.rotation = Quaternion.LookRotation(velocity); // Rotate the vehicle towards the desired Velocity. } }