I seem to be having the same problem mentioned in two other posts but when I checked my code against the lecture’s update I was not able to identify the mistake. The fields in the Inspector look filled in too. Any suggestions how to fix the issue would be appreciated. Thanks! My EnemyPathing.cs is shown below and image attached.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyPathing : MonoBehaviour
{
WaveConfig waveConfig; //type is WaveConfig (scriptable object)
List<Transform> waypoints;
int waypointIndex = 0; //lists start from zero like arrays
// 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()
{
Move();
}
public void SetWaveConfig(WaveConfig waveConfig)
{
this.waveConfig = waveConfig; // "this" refers to waveConfig in this class (EnemyPathing) which
// is assigned the waceConfig value passed through the SetWaveConfig method
}
private void Move()
{
if (waypointIndex <= waypoints.Count - 1) // lists use Count not Length due to non fixed length
{
var targetPosition = waypoints[waypointIndex].transform.position;
var movementThisFrame = waveConfig.GetMoveSpeed()* Time.deltaTime;
transform.position = Vector2.MoveTowards
(transform.position, targetPosition, movementThisFrame); ;
if (transform.position == targetPosition)
{
waypointIndex++;
}
}
else
{
Destroy(gameObject);
}
}
}