I’m stuck at this lecture 99
the error said in the console NullReferenceException
The variable enemyPrefab of WaveConfig has not been assigned.
You should probably need to assign the enemyPrefab variable of the WaveConfig script in the inspector.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
[SerializeField] List waveConfigs;
int startingWave = 0;
// Start is called before the first frame update
void Start()
{
var CurrentWave = waveConfigs[startingWave];
StartCoroutine(SpawnAllEnemiesInWave(CurrentWave));
}
private IEnumerator SpawnAllEnemiesInWave(WaveConfig waveConfig)
{
for (int enemyCount = 0; enemyCount < waveConfig.GetNumberOfEnemies(); enemyCount++)
{
Instantiate(waveConfig.GetEnemyPrefab(), waveConfig.GetWayPoints()[0].transform.position, Quaternion.identity);
yield return new WaitForSeconds(waveConfig.GetTimeBetweenSpawns());
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu (menuName = “Enemy Waves Config”)]
public class WaveConfig : ScriptableObject
{
[SerializeField] GameObject EnemyPrefab;
[SerializeField] GameObject pathPrefab;
[SerializeField] float timeBetweenSpawns = 0.1f;
[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 GetTimeBetweenSpawns() { return timeBetweenSpawns; }
public float GetSpawnRandomFactor() { return spawnRandomFactor; }
public int GetNumberOfEnemies() { return numberOfEnemies; }
public float GetMoveSpeed() { return moveSpeed; }
}
please help me
thanks