コード例 #1
0
ファイル: EnemySpawner.cs プロジェクト: VeRTeXR/SnakeRPG
        private void SpawnEnemy()
        {
            var heroOnGrid  = _levelGrid.GetHeroOnGridPositionList();
            var enemyOnGrid = _levelGrid.GetEnemyOnGridPositionList();

            do
            {
                _newGridPosition = new Vector2Int(Random.Range(0, _levelWidth), Random.Range(0, _levelHeight));
            } while (_caravanController.GetCaravanGridPositionList().IndexOf(_newGridPosition) != -1 &&
                     heroOnGrid.IndexOf(_newGridPosition) != -1 &&
                     enemyOnGrid.IndexOf(_newGridPosition) != -1);

            var enemyObject = new GameObject("Enemy", typeof(SpriteRenderer));

            enemyObject.transform.position = new Vector3(_newGridPosition.x, _newGridPosition.y);
            var enemyEntity = enemyObject.AddComponent <EnemyEntity>();

            enemyEntity.Setup(GetRandomSprite());
            _levelGrid.AppendEnemyPosition(_newGridPosition);
            _enemyOccupiedGridPosition.Add(_newGridPosition);
            _gridPositionEntityPair.Add(_newGridPosition, enemyEntity);
        }