WaveObserver gère le nombre d'ennemi à créer et assure d'arreter la création d'ennemis supplémentaires. SpawnerTile détermine un intervalle aléatoire automatiquement après chaque création d'ennemi. La première intervalle a plus de chance d'être plus courte que les intervalles suivantes. Config01 est le scriptable object de type LevelConfig Suppression de commentaires de tests
44 lines
1011 B
C#
44 lines
1011 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Gather And Defend/Levels/LevelConfig")]
|
|
public class LevelConfig : ScriptableObject
|
|
{
|
|
[SerializeField]
|
|
private List<EnemyType> _constantSpawn = new List<EnemyType>();
|
|
[SerializeField]
|
|
private float _gameDuration = 0;
|
|
public List<EnemyType> ConstantSpawn
|
|
{
|
|
get
|
|
{
|
|
return _constantSpawn;
|
|
}
|
|
}
|
|
public float GetInterval()
|
|
{
|
|
float interval = SumCount().ToFloat() / _gameDuration * 0.01f;
|
|
return interval;
|
|
}
|
|
public EnemyType GetRandomSpawn()
|
|
{
|
|
if (_constantSpawn.Count == 1)
|
|
{
|
|
return _constantSpawn[0];
|
|
}
|
|
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)];
|
|
}
|
|
|
|
private int SumCount()
|
|
{
|
|
int sum = 0;
|
|
foreach (EnemyType enemy in _constantSpawn)
|
|
{
|
|
sum += enemy.Count;
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
}
|