Doesn't work MoveTowards and Lerp

Hello guys! Had a problem: got 2 classes: EnemyCreate:

using UnityEngine;
using System.Collections;

public class EnemyCreate : MonoBehaviour {

	public GameObject enemyObject;

	void Start () {
		StartCoroutine(CreatingEnemy());
	}
		
	void Update (){
		
	}

	IEnumerator CreatingEnemy()
	{
		while(true)
		{
			CreateEnemy();
			yield return new WaitForSeconds(1);
		}
	}

	void CreateEnemy()
	{
			GameObject enemy = (GameObject)Instantiate(enemyObject);
			enemy.transform.parent = this.gameObject.transform;
		}
	}
}

and Enemy:

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {	
	Transform[] wayPoint;
	float enemySpeed = 5.0f;	
	void Start () {
		GetWay();
	}

	void GetWay()
	{
		int waysCount = GameObject.FindGameObjectWithTag ("Ways").transform.childCount;
		int wayNumber = Random.Range (1, waysCount+1);
		int wayPoints = GameObject.FindGameObjectWithTag ("Ways").transform.FindChild 
			("Way" + wayNumber).childCount;
		// array of enemy way points
		wayPoint = new Transform[wayPoints];
		for (int i = 0; i < wayPoints; i++) {
			wayPoint  *= GameObject.FindGameObjectWithTag ("Ways").transform.FindChild* 
  •  		("Way" + wayNumber).transform.FindChild ("Point" + (i + 1));*
    
  •  }*
    
  • }*

  • void Update()*

  • {*

_ transform.position = Vector3.MoveTowards (transform.position, wayPoint [0].position, enemySpeed * Time.deltaTime);_

  • }*

}
This doesn’t work:
transform.position = Vector3.MoveTowards (transform.position, wayPoint [0].position, enemySpeed * Time.deltaTime);
The code creates enemies with different ways to move, wayPoint[0] exist, all enemies has the same wayPoint[0] and start point(point where enemy instantiate). ATM I want to make enemy move just from start point to wayPoint[0].
Can someone help me?

Hello !
First of all, I noticed your EnemyCreate.cs will never stop creating enemies. Intended or not, this may make your debugging harder. I recommend creating only 1, testing it, and multiplying the results when they work.

I also see you have a lot going on in your “GetWay” function. I assume you have an Empty game object named “Ways” and you want your enemies to traverse those waypoints randomly, correct?

I would start by getting a reference to those waypoints on Start(), instead of looking for them every time you want a new waypoint.
I would do this by tagging my waypoints, and then using your current MoveTowards code to move towards the next waypoint. When we get too close (you can change this to a bigger number like 0.01f) then we get another random waypoint from our references.

GameObject[] waypointsRef;
Vector3 destination;

void Start()
{
    waypointsRef = GameObject.FindGameObjectsWithTag("Waypoints");
    GetWaypoint();
}

Vector3 GetWaypoint()
{
    destination = waypointsRef[Random.Range(0, waypointsRef.Length - 1)].trasnform.position;
}

void Update()
{
    Vector3 source = transform.position;
    if ((destination - source).magnitude < Mathf.Epsilon)
        transform.position = Vector3.MoveTowards(source,destination, enemySpeed * Time.deltaTime);
    else
        GetWaypoint();
}

Let me know how it goes.