I need help with a tower defence game I'm making

I’ve started making a tower defence game and I’m having a problem with the enemy AI as for whatever reason It is going straight to the end and not going to the path I created. I assume that it is because I’m going off a fairly old Brackeys video and not using pathfinding. I’ve posted the code I’m using down below. If you have any suggestions or know how to fix the problem i’m having that would be appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyMovement : MonoBehaviour
{
   public float speed = 10f; 

   private Vector3 vector3;

  public Transform target;
   private int wavepointIndex = 0;

void Start()
{
  target = Waypoints1.points[0];
} 


void Update()
{
   Vector3 dir = target.position - transform.position;
    transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);

    if (Vector3.Distance(transform.position, target.position) <= 0.2f)
    {
       GetNextWaypoint();
     } }

   

   void GetNextWaypoint()
   {
      if (wavepointIndex >= Waypoints1.points.Length - 1)
      {
         Destroy(gameObject);
      }
      wavepointIndex++;
      target = Waypoints1.points[wavepointIndex];
   }
   
}

The logic to transition to the next waypoint seems okay to me. I’d just debug this to add some information to help you understand what’s happening. For example, before you call GetNextWaypoint, you might Debug.Log what the two positions were, and the distance it calculates between them, along with the current waypointIndex.

I’m also assuming you’ve placed your waypoints correctly into this object, such that it has several waypoints, and that the waypoints are reasonably far apart.