Hey folks!
I have a script that uses a Class inside a list and serialized system. But, for some reason, it is messing up all my Inspector when I try to use it. Anyone had this issue before? Any idea how to solve it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class WaveSetup
{
public string name;
public float delay;
public GameObject enemy;
public int spawnAmount;
public int waveTime;
}
[System.Serializable]
public class Wave
{
public string name;
public List<WaveSetup> setup;
}
public class WaveController : MonoBehaviour
{
public float TimeWaves = 1f;
public List<Wave> waves;
private int waveNumber = 0;
private int enemyCount = 0;
private Wave currentWave;
private WaveSetup currentSetup;
void Start()
{
currentWave = waves[waveNumber];
currentSetup = currentWave.setup[0];
print(currentWave.name);
StartCoroutine("SpawnLoop");
}
private void Update()
{
print("Wave: " + waveNumber + "/" + waves.Count);
if (waveNumber >= waves.Count)
{
print("End of Waves");
StopSpawnLoop();
Destroy(gameObject);
}
}
IEnumerator SpawnLoop()
{
while (true)
{
if (currentSetup.spawnAmount != 0 && enemyCount < currentSetup.spawnAmount)
{
Instantiate(currentSetup.enemy, gameObject.transform.position, currentSetup.enemy.transform.rotation);
enemyCount++;
print(enemyCount + "/" + currentSetup.spawnAmount);
yield return new WaitForSeconds(currentSetup.delay);
}
if (enemyCount == currentSetup.spawnAmount && waveNumber < waves.Count)
{
yield return new WaitForSeconds(currentSetup.waveTime);
nextWave();
}
yield return null;
}
}
public void nextWave()
{
print("Callou!");
waveNumber++;
currentWave = waves[waveNumber];
currentSetup = currentWave.setup[0];
enemyCount = 0;
print(currentWave.name);
}
public void StopSpawnLoop()
{
StopCoroutine(SpawnLoop());
}
}