Esempio n. 1
0
    IEnumerator SpawnWave(int wave)
    {
        player.GetHealing(data.healthRegenPerWave);
        BasicEnemy randomEnemy = null;

        while (randomEnemy == enemyToSpawn || randomEnemy == null)
        {
            randomEnemy = enemiesList[Random.Range(0, enemiesList.Count)];
        }
        enemyToSpawn = randomEnemy;
        int enemiesToSpawn = enemyToSpawn.CalculateEnemiesToSpawn(wave);

        for (int i = 0; i < enemiesToSpawn; i++)
        {
            float      horizontalMargin = 30 * data.scaling;
            float      spawnX           = Random.Range(-Screen.height / 2f * 9f / 20f + horizontalMargin, Screen.height / 2f * 9f / 20f - horizontalMargin);
            float      spawnY           = Screen.height * (0.5f + data.entityBorder);
            BasicEnemy spawnedEnemy     = Instantiate(enemyToSpawn, new Vector3(spawnX, spawnY, 0), Quaternion.Euler(0, 0, 0), enemiesParent);
            spawnedEnemy.health = spawnedEnemy.CalculateHealth(wave);
            spawnedEnemy.powerUpPercentChance = spawnedEnemy.health * data.powerUpPercentChancePerHealth;
            spawnedEnemy.speed          = spawnedEnemy.CalculateSpeed(wave);
            spawnedEnemy.damage         = spawnedEnemy.CalculateDamage(wave);
            spawnedEnemy.gameController = this;
            spawnedEnemy.data           = data;
            yield return(new WaitForSeconds(spawnedEnemy.CalculateSpawnTime(wave)));
        }
    }