moving one spot to another problem

It seems so simple yet it’s driving me crazy. I just want this enemy npc to move back and forth between these two predetermined waypoints. I’ve looked up patrol stuff but everything I look up is a little advanced or patrolling without waypoints. right now it just goes back and forth between waypoints, it does rotate, but it does it in instantaneously and I was trying to get it to “walk” between the points.

	void Start () {
		CurrentState = (int)states.Wander;
		gameObject.renderer.material.color = Color.yellow;
		player = GameObject.FindGameObjectWithTag("player");
		waypoints[0] = new Vector3(-35f,2.1f,22f);
		waypoints[1] = new Vector3(-20,2.1f,22f);
		i = 0;
		t = Time.deltaTime;
	}
	
	// Update is called once per frame
	void Update () {
		if (CurrentState == (int)states.Wander)
		{
			StartCoroutine(wayTravel());
			CurrentState = (int)states.Patrol;
		}

		if (CurrentState == (int)states.Searching)
		{

		}
		if (CurrentState == (int)states.Attacking)
		{
			transform.LookAt(player.transform.position);

		}
		//Vector3 playloc = transform.Translate
	}
	IEnumerator wayTravel()
	{
		transform.LookAt(waypoints[i]);
		transform.position = Vector3.Lerp (transform.localPosition,waypoints[i],t*walkSpeed * 1.0f);
		t += Time.deltaTime;
		i++;
		
		if (i == waypoints.Length)
		{
			i = 0;
		}
		yield return new WaitForSeconds(2);
	CurrentState = (int)states.Wander;

	}

Ive also tried without the time.delta time and used a constant instead in the lerp but that yielded the same results. Actually what i have posted now doesn’t make it to the right spot, it barely moves in the direction its suppose to then returns, but still instantaneously.

Again seems like it would be simple but I want this because later I plan on having the npc move to the last known player position which should essentially use the same code with a different target destination in the lerp

Thanks in advance, any feedback is appreciated

i’m thinking lerp maybe shouldn’t be in the enumerator? idk I just need this jerk to go back and forth between these two points without using any imported packages.

you need to do somethink along these lines …

// pseudo code

IEnumerator wayTravel()
{
    while( CurrentState == state.wander )
    {
        LoockAt( currentWaypoint );
        Move( direction * speed * deltaTime );
    
        if( Distance( myPosition, currentWaypoint ) < wayPointReached )
            currentWaypoint = nextWaypoint;

        yield return null;
    }

}

ahh after playing with it a bit i finally got it to move right. Just had to look more closely that last parameter in lerp was basically the percent of interpolated line between the destinations. Thanks!