I Currently have a problem with the enemy wave script and it’s Serializable nature
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class EnemyWave : MonoBehaviour{
public int pathIndex;
public float startSpawnTimeInSeconds;
public float timeBetweenSpawnsInSeconds = 1f;
public List<GameObject> listOfEnemies = new List<GameObject>();
in order for serializable to be recognized by Visual studio I had to add “using system” to my code which is fine but the book shows that it’s not a requirement.
However, while following along in the book and finishing up the wave manager I went to expand element 0 but I only saw a empty space waiting for an object with the enemy wave script attached. Ultimately I can just create an empty object and set the variables in it and place the object in the empty slot.
But, since that’s not how the book details the situation I wanna know what I need to do to make unity preform the way the book says it should act
Below is a image of the Wave manager’s current behavior
.
here is my current code for the wave manager
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
public class WaveMAnager : MonoBehaviour {
public static WaveMAnager Instance;
public List<EnemyWave> enemyWaves = new List<EnemyWave>();
private float elapsedTime = 0f;
private EnemyWave activeWave;
private float spawnCounter = 0f;
private List<EnemyWave> activatedWaves = new List<EnemyWave>();
void Awake()
{
Instance = this;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
elapsedTime += Time.deltaTime;
SearchForWave();
UpdateActiveWave();
}
private void SearchForWave()
{
foreach(EnemyWave enemyWave in enemyWaves)
{
if (!activatedWaves.Contains(enemyWave) && enemyWave.startSpawnTimeInSeconds <= elapsedTime)
{
activeWave = enemyWave;
activatedWaves.Add(enemyWave);
spawnCounter = 0f;
break;
}
}
}
private void UpdateActiveWave()
{
if (activeWave != null)
{
spawnCounter += Time.deltaTime;
if(spawnCounter >= activeWave.timeBetweenSpawnsInSeconds)
{
spawnCounter = 0f;
if (activeWave.listOfEnemies.Count != 0)
{
GameObject enemy = (GameObject)Instantiate(activeWave.listOfEnemies[0], WaypointManager.Instance.GetSpawnPosition(activeWave.pathIndex), Quaternion.identity);
enemy.GetComponent<Enemy>().pathIndex = activeWave.pathIndex;
activeWave.listOfEnemies.RemoveAt(0);
}
else
{
activeWave = null;
if(activatedWaves.Count == enemyWaves.Count)
{
}
}
}
}
}
public void StopSpawning()
{
elapsedTime = 0;
spawnCounter = 0;
activeWave = null;
activatedWaves.Clear();
enabled = false;
}
}