I’ve not yet fixed it and I’ve also not checked the code to the Project Changes.
This is the code for “EnemyPathway.cs.”
{
WaveConfig waveConfig;
List<Transform> waypoints;
int waypointIndex = 0;
// Start is called before the first frame update
void Start()
{
waypoints = waveConfig.GetWaypoints();
transform.position = waypoints[waypointIndex].transform.position;
}
// Update is called once per frame
void Update()
{
movement();
}
public void SetEnemyPath(WaveConfig waveConfig)
{
this.waveConfig = waveConfig;
}
private void movement()
{
if (waypointIndex <= waypoints.Count - 1)
{
var targetPos = waypoints[waypointIndex].transform.position;
var movementThisFrame = waveConfig.GetMoveSpeed() * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, targetPos, movementThisFrame);
if (transform.position == targetPos)
{
waypointIndex++;
}
}
else
{
Destroy(gameObject);
}
}
}
If it helps, this is the code for the WaveConfig scriptable object file.
{
[SerializeField] GameObject enemyPrefab;
[SerializeField] GameObject pathPrefab;
[SerializeField] float timeBetweenSpawns = 0.5f;
[SerializeField] float spawnRandomFactor = 0.4f;
[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 GetTimeBetweenSpawns()
{
return timeBetweenSpawns;
}
public float GetSpawnRandomFactor()
{
return spawnRandomFactor;
}
public int GetNumberOfEnemies() { return numberOfEnemies; }
public float GetMoveSpeed() { return moveSpeed; }
}