using UnityEngine;
public class EnemyController : MonoBehaviour
{
public float speed = 2f;
public Transform pointA, pointB;
private Vector3 target;
void Start()
{
target = pointB.position;
}
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
if (Vector3.Distance(transform.position, target) < 0.1f)
{
target = target == pointA.position ? pointB.position : pointA.position;
}
}
}