Why do the enemies not follow me?

using UnityEngine;
using System.Collections;

public class EAI : MonoBehaviour {
	public GameObject targetPos;
	public float speed = 2f;
	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {


		float step = speed * Time.deltaTime;
		//transform.position = Vector3.MoveTowards(targetPos.gameObject.transform.position.x, targetPos.gameObject.transform.position.y, step);
		transform.position = Vector3.MoveTowards (transform.position, targetPos.gameObject.transform.position, step);
	}
}

Well if that code doesn’t work then try this other code out:

this.transform.position = Vector3.Lerp(transform.position, targetPos.transform.position, step);

To have it follow a prefab you can’t just drag your prefab into the inspector since that doesn’t work, sad day I know. To get around this problem you will have to find your prefab as soon as it enters the game by its TAG or NAME. Here is some example code of how I might find the prefab by its tag:

  void Update () {
      if(FindTheTarget("Player") != null){
         float step = speed * Time.deltaTime;
         targetPos = FindTheClosestTarget("Player");
         transform.position = Vector3.MoveTowards (transform.position, targetPos.transform.position, step);
      }
  }
GameObject FindTheTarget(TagToSearch:String){ 
     GameObject target; 
     target = GameObject.FindGameObjectWithTag(TagToSearch); 
     return target;
 }

This is counting on the fact that there is only going to be one player. If you want to have more than one player to check for then you will need to make target an array and loop through that array for the closest one.(That is if you wanted to find the closest target).

Let me know how this goes for you.

An alternative way of writing this would be the following:

 void Update () {
       GameObject target = GameObject.FindGameObjectWithTag("Player"); 
       if(target != null){
          float step = speed * Time.deltaTime;
          transform.position = Vector3.MoveTowards (transform.position, target.transform.position, step);
       }
   }