예제 #1
0
    private void SpawnEnemy()
    {
        var newEnemy = Instantiate(enemies[enemyIndex], transform.position, Quaternion.identity);

        newEnemy.position           = position;
        newEnemy.transform.position = GridUtils.GetWorldPos(position);

        board.AddEnemy(newEnemy);
    }
    public void SpawnEnemy(int wave)
    {
        List <GridSystem.Cell> entrances = GameManager.Instance.CurrentLevelManager.GameBoardSystem.GameGridSystem.MainGameGrid.Entrances;
        int entrance = Random.Range(0, entrances.Count);

        int temp = Random.Range(0, 4);

        if (wave == 1)
        {
            temp = 0;
        }
        if (wave == 2)
        {
            temp = 1;
        }
        if (wave == 3)
        {
            temp = 2;
        }
        if (wave == 4)
        {
            temp = 3;
        }
        if (wave % 5 == 0)
        {
            temp = Random.Range(4, 7);
        }
        List <GridSystem.Cell> path;

        if ((Enemy.Type)temp != Enemy.Type.Flying && (Enemy.Type)temp != Enemy.Type.BossFly)
        {
            path = GameManager.Instance.SearchPathFrom(entrances[entrance].X, entrances[entrance].Y);
        }
        else
        {
            path = GameManager.Instance.SearchFlyingPath(entrances[entrance].X, entrances[entrance].Y);
        }
        var tiles = new List <GameBoard.Tile>();

        foreach (GridSystem.Cell t in path)
        {
            tiles.Add(_gameBoard.BoardTiles[t.X, t.Y]);
        }

        GridSystem.Cell startCell = entrances[0];
        GameBoard.Tile  startTile = tiles[0];


        Vector3 spawnPosition = startTile.Position;

        GameObject enemeyGameObject = Instantiate(Enemies[temp], spawnPosition, Quaternion.identity) as GameObject;

        if (enemeyGameObject != null)
        {
            enemeyGameObject.transform.SetParent(this.transform);
            //Enemies.Add(enemeyGameObject);
            Enemy enemy = enemeyGameObject.GetComponent <Enemy>();
            _enemies.Add(enemy);
            enemy.SetupEnemy(startCell.X, startCell.Y, tiles, path, (Enemy.Type)temp);
            _gameBoard.AddEnemy(enemy);
        }
    }