private void OnDestoryEnemy(object sender, GameObject gameObject) { Type t = gameObject.GetType(); if (t != typeof(SmallAsteroid)) { EnemiesCount--; if (gameObject is Asteroid) { int smallAsteroids = _rnd.Next(2, 4); for (int i = 0; i < smallAsteroids; i++) { CreateEnemy?.Invoke(gameObject.Pivot, EnemyType.SmallAsteroid); } } EnemyType enemyType = ChoseEnemyType(); if (EnemiesCount < _maxEnemiesInScene) { AddEnemyToSpawnQueue(enemyType, _rnd.Next(0, _maxSpawnDelayTime)); } } }
public void Update() { foreach (var spawingEnemy in _spawingEnemies) { if (spawingEnemy.TimeToSpawn <= 0) { CreateEnemy?.Invoke(this, spawingEnemy.EnemyType); _removingEnemies.Add(spawingEnemy); } else { spawingEnemy.TimeToSpawn--; } } CheckRemoving(); }