Fixed spawning decrementation and changing spawner objectives dynamically

This commit is contained in:
Ader Alisma 01 2024-03-02 16:26:47 -05:00
parent 8921c898ec
commit bc4b4c30a8
4 changed files with 23 additions and 11 deletions

View File

@ -17,6 +17,8 @@ MonoBehaviour:
_count: 4 _count: 4
- _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} - _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
_count: 4 _count: 4
- _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
_count: 6
_nestedGroupSpawn: _nestedGroupSpawn:
- groupSpawn: - groupSpawn:
- _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} - _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}

View File

@ -1,4 +1,3 @@
using Codice.CM.Client.Differences;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;

View File

@ -18,6 +18,7 @@ public class WaveConfig : ScriptableObject
private float _gameDuration = 1; private float _gameDuration = 1;
private float _enemySpawndOnStart = 0; private float _enemySpawndOnStart = 0;
private int _enemySum = 0; private int _enemySum = 0;
private List<GameObject> _constraintList = new List<GameObject>();
public List<EnemyType> ConstantSpawn public List<EnemyType> ConstantSpawn
{ {
get get
@ -63,15 +64,25 @@ public class WaveConfig : ScriptableObject
{ {
return _constantSpawn[0]; return _constantSpawn[0];
} else if (constraint != null) } else if (constraint != null)
{
if (!_constraintList.Contains(constraint))
{
_constraintList.Add(constraint);
}
if (_constraintList.Count < _constantSpawn.Count)
{ {
EnemyType randomEnemy; EnemyType randomEnemy;
do do
{ {
randomEnemy = _constantSpawn[Random.Range(0, _constantSpawn.Count)]; randomEnemy = _constantSpawn[Random.Range(0, _constantSpawn.Count)];
} while (randomEnemy.GetEnemyObject() == constraint); } while (_constraintList.Contains(randomEnemy.GetEnemyObject()));
return randomEnemy; return randomEnemy;
} else
{
return null;
} }
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)]; }
return _constantSpawn[Random.Range(0, _constantSpawn.Count)];
} }
/** /**

View File

@ -81,7 +81,7 @@ public class WaveObserver : Singleton<WaveObserver>
spawnerSubject.ChangeSpawnSpeed(_levelConfig.Interval * _spawnerTiming); spawnerSubject.ChangeSpawnSpeed(_levelConfig.Interval * _spawnerTiming);
for (int spawnIndex = 0; spawnIndex < _copyConstantSpawn.Count; spawnIndex++) for (int spawnIndex = 0; spawnIndex < _copyConstantSpawn.Count; spawnIndex++)
{ {
if (_copyConstantSpawn[spawnIndex] == 0) if (_copyConstantSpawn[spawnIndex] == 0) //Doesn't compare this iteration because it's already empty
{ {
Debug.Log("--I'm empty--"); Debug.Log("--I'm empty--");
continue; continue;
@ -97,15 +97,15 @@ public class WaveObserver : Singleton<WaveObserver>
{ {
if (spawner.Prefab.Equals(paramPrefab)) if (spawner.Prefab.Equals(paramPrefab))
{ {
GameObject randomEnemy = _levelConfig.GetRandomSpawn(paramPrefab).GetEnemyObject(); EnemyType randomEnemy = _levelConfig.GetRandomSpawn(paramPrefab);
if (randomEnemy == spawner.Prefab) if (randomEnemy?.GetEnemyObject() == spawner.Prefab || randomEnemy == null)
{ {
spawner.StopSpawn(); spawner.StopSpawn();
Debug.Log("----Spawn Stopped----"); Debug.Log("----Spawn Stopped----");
} }
else else
{ {
spawner.Prefab = randomEnemy; spawner.Prefab = randomEnemy.GetEnemyObject();
Debug.Log("----Spawn Changed!!!----"); Debug.Log("----Spawn Changed!!!----");
} }
} }