this error appeared and I couldn’t find a solution. Visual Studio does not point out any errors or alerts.
error:
NullReferenceException: Object reference not set to an instance of an object
EnemyPathing.Move () (at Assets/Scripts/EnemyPathing.cs:34)
EnemyPathing.Update () (at Assets/Scripts/EnemyPathing.cs:25)
my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyPathing : MonoBehaviour
{
WaveConfig waveConfig;
List wayPoints;
int wayPointIndex = 0;
// Use this for initialization
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;
}
private void Move()
{
if (wayPointIndex <= wayPoints.Count - 1)
{
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);
}
}
}