private void InitEnemy() { SpawnEnemy enemyTemp = null; int index = 1; foreach (Transform trams in transform) { enemyTemp = trams.GetOrAddComponent <SpawnEnemy>(); enemyTemp.Init(index, RemoveEnemyCallBack); inactiveEnemies.Add(enemyTemp); index++; } }
public void Spawn() { int count = GetSpawnNum(); SpawnEnemy enemyTemp = null; HashSet <SpawnEnemy> .Enumerator temp = inactiveEnemies.GetEnumerator(); for (int i = 0; i < count; i++) { if (temp.MoveNext()) { enemyTemp = temp.Current; activeEnemies.Add(enemyTemp); enemyTemp.Spawn(); } } foreach (SpawnEnemy enemy in activeEnemies) { inactiveEnemies.Remove(enemy); } }
private void RemoveEnemyCallBack(SpawnEnemy enemy) { activeEnemies.Remove(enemy); Spawn(); }