When i play my Level scene the enemy spawn fine but if i load the scene from the start menu no enemy spawn.
this is the error that pops up
NullReferenceException: Object reference not set to an instance of an object
EnemyPathing.move () (at Assets/scripts/EnemyPathing.cs:31)
EnemyPathing.Update () (at Assets/scripts/EnemyPathing.cs:20)
and the EnemyPathing script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyPathing : MonoBehaviour
{
waveconfig waveConfig;
List<Transform> waypoints;
int waypointIndex = 0;
private void Start()
{
waypoints = waveConfig.GetWaypoints();
transform.position = waypoints[waypointIndex].transform.position;
}
private 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);
}
}
}
also the waves in the wave Configs list disappear when loading from the menu
playing from level 1 scene
playing after loading from start menu
please help iv been trying to figure this one out for a while now
thank you