Beispiel #1
0
	public void CreateEnemiesWaves(int a_WavesCount, int a_MinEnemyCount, int a_MaxEnemyCount, int timeBetwenEnemySpawnMin, int timeBetwenEnemySpawnMax)
	{
		if (WavesList == null) {
			WavesList = new List<LevelEnemiesWave> ();
		} else {
			WavesList.Clear ();
		}

		System.Random prng = new System.Random ();

		for(int i = 0; i < a_WavesCount; i++)
		{			
			int l_EnemiesInWave = prng.Next (a_MinEnemyCount, a_MaxEnemyCount);
			float l_TimeBetweenSpawns = prng.Next (timeBetwenEnemySpawnMin, timeBetwenEnemySpawnMax) * 0.1f;
			LevelEnemiesWave newEnemyWave = new LevelEnemiesWave (l_EnemiesInWave, l_TimeBetweenSpawns);
			WavesList.Add (newEnemyWave);
		}
	}
	void NextWave() {
		currentWaveNumber++;
		if (currentWaveNumber - 1 < wavesCount)
		{
			GameStatesManager.Instance.GameViewUI.UpdateEnemiesWaves (currentWaveNumber);
			currentWave = wavesList [currentWaveNumber - 1];
			enemiesRemainingToSpawn = currentWave.enemiesInWave;
			enemiesRemainingAlive = enemiesRemainingToSpawn;

			if (ObjectPoolManager.instance.poolSize < enemiesRemainingToSpawn)
			{
				ObjectPoolManager.instance.CreatePool (EnenmyPrefab, enemiesRemainingToSpawn);
			}
		}
		else if(currentWaveNumber - 1 == wavesList.Count && enemiesRemainingAlive == 0)
		{
			GameStatesManager.Instance.GoToWonState ();
		}
	}
	public void ResetEnemiesSpawner()
	{
		m_Initialized = false;
		currentLevel = null;
		wavesList.Clear ();
		currentWave = null;
		currentWaveNumber = 0;
		enemiesRemainingAlive = 0;
		enemiesRemainingToSpawn = 0;
		nextSpawnTime = 0;
		StopEnemiesAndHide ();
	}