For some odd reason, enemy keeps moving towards one point

If I add the Wave1 scriptable object to the EnemyPathing.cs component of the Enemy game object, when I press play it moves the way it should: so from the first waypoint to the second at the speed which I set.
However if I add the second Wave2 scriptable object, that contains the Path(1) prefab as Path Prefab, it doesn’t work the same way, even though Path(1) also contains its own waypoints different from the Path(0), contained in the Wave1 scriptable object. For some unexplainable reason, when I pressed Play, and my Enemy GO had the Wave2 script. obj. it glued to one of the waypoints (at the position of x = 0.06 and y = 6.21, randomly chosen by me) and it didn’t move. If I tried to move it manually whilst in Play mode, it would grind steadily back to the position of that waypoint it previously glued itself onto, until it reaches it, and stops again.
Then, I tmoved the Path(1) game object lower, to see if ti follows the same waypoint of the path again, but Enemy stuck to the previous position of the waypoint that it had before I moved the Path(1) game object. And now whichever new Path(n) I create, attach it to a Wave(n) scriptable object, the Enemy instance still sticks to that same goddamn former waypoint position of x = 0.06 and y = 6.21 . I tried issuing a new Enemy instance and the problem persists.
The yellow diamonds below in the Scene window mark the waypoints of Path(0) and the blue mark the waypoints of Path(2), a new Path game object I made to see if the problem persists.
PNG

I hope I’m clear in what I mean here because I’ve been banging my head on this problem for some time and I’m a bit fuzzy. Here’s also the WaveConfig.cs code

    [SerializeField] GameObject enemyPrefab;
    [SerializeField] GameObject pathPrefab;
    [SerializeField] float timeBetweenSpawn = 0.5f;
    [SerializeField] float spawnRandomFactor = 0.3f;
    [SerializeField] int numberOfEnemies = 5;
    [SerializeField] float moveSpeed = 2f;

    public GameObject GetEnemyPrefab() { return enemyPrefab; }

    public List<Transform> GetWaypoints()
    {
        var waveWaypoints = new List<Transform>();
        foreach (Transform child in pathPrefab.transform)
        {
            waveWaypoints.Add(child);
        }
        return waveWaypoints;
    }

    public float GetTimeBetweenSpawn() { return timeBetweenSpawn; }`

and the EnemyPathing.cs code

    [SerializeField] WaveConfig waveConfig;
    List<Transform> waypoints;
    [SerializeField] float moveSpeed = 2f;
    int waypointIndex = 0;

	// Use this for initialization
	void Start () {
        waypoints = waveConfig.GetWaypoints();
        transform.position = waypoints[waypointIndex].transform.position;
	}

Privacy & Terms