Exemple #1
0
    private void Spawn(EnemyToSpawn e)
    {
        GameObject        spawnedEnemy = Instantiate(e.prefab, transform.position, Quaternion.identity, EnemyToSpawn.parent.transform);
        WaypointNavigator navigator    = spawnedEnemy.GetComponent <WaypointNavigator>();

        navigator.currentWaypoint = startingWaypoint;
    }
Exemple #2
0
    void Spawn()
    {
        // If the player has no health left...
        if (playerHealth.currentHealth < 0f)
        {
            // ... exit the function.
            return;
        }

        // Find a random index between zero and one less than the number of spawn points.
        int spawnPointIndex = Random.Range(0, spawnPoints.Length);

        GameObject enemy = null;

        // Pick a enemy to spawn.
        while (enemy == null)
        {
            // Pick a random enemy to try and spawn.
            EnemyToSpawn possibleEnemy = enemies[Random.Range(0, enemies.Length)];

            // Check and see if the enemy will be spawned.
            if (possibleEnemy.chanceOfSpawn > 0)
            {
                if (Random.Range(1, 100) < possibleEnemy.chanceOfSpawn)
                {
                    enemy = possibleEnemy.enemy;
                }
            }
        }

        // Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation.
        Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
    }
    /*
     * Spawn wave every X seconds
     *
     */
    IEnumerator NewSpawnWave()
    {
        for (int i = 0; i < lstWaves[wave - 1].enemies.Count; i++)
        {
            EnemyToSpawn toSpawn = lstWaves[wave - 1].enemies[i];

            for (int x = 0; x < toSpawn.amount; x++)
            {
                GameObject enemy = Instantiate(toSpawn.prefab);
                enemy.transform.position = spawn.position;
                enemy.GetComponent <EnemyEntity>().wavesController = this;
                enemiesAlive += 1;
                yield return(new WaitForSeconds(lstWaves[wave - 1].rate));
            }
        }
        wave++;
    }
Exemple #4
0
    // Takes the group of enemies and creates EnemyToSpawn objects with the location
    // within the spawn zone of where to spawn them
    private void PopulateSpawnZone(EnemyGroup group, SpawnZone spawnZone)
    {
        List <GameAgentStats> enemyStats         = group.GetEnemiesStatsForSpawn();
        List <Pos>            zoneTiles          = spawnZone.GetUnpopulatedZoneTiles();
        List <Pos>            populatedZoneTiles = new List <Pos>();

        // Random distribution in zone
        List <int> exclusion = new List <int>();

        foreach (GameAgentStats stats in enemyStats)
        {
            int randomIndex = Utility.GetRandomIntWithExclusion(0, zoneTiles.Count - 1, rng, exclusion);
            Pos enemyPos    = new Pos((int)zoneTiles[randomIndex].x, (int)zoneTiles[randomIndex].y);
            populatedZoneTiles.Add(zoneTiles[randomIndex]);
            EnemyToSpawn enemy = new EnemyToSpawn(enemyPos, stats);

            exclusion.Add(randomIndex);
            enemies.Add(enemy);
        }
        spawnZone.PopulateTiles(populatedZoneTiles);
    }
Exemple #5
0
 public EnemySpawned(EnemyToSpawn enemy, Vector2 position, float time)
 {
     this.enemy    = enemy;
     this.position = position;
     this.time     = time;
 }