public void SpawnNewMobs(MobScriptable mobScriptable, int amount) { this.ForceInitialization(); List <TileMapComponnent> tileMapWithoutObjectsList = _tileMapChildrensList .Where(e => !e.HasObstacle && e.Side != EnumSide.BOTTOM && e.Side != EnumSide.BOTTOM_RIGHT && e.Side != EnumSide.LEFT_BOTTOM).ToList(); List <int> indexToSpanw = new List <int>(); while (amount != 0) { int index = UnityEngine.Random.Range(0, tileMapWithoutObjectsList.Count); if (indexToSpanw.Any(e => e == index)) { continue; } else { indexToSpanw.Add(index); amount--; } } foreach (int index in indexToSpanw) { TileMapComponnent tileMap = tileMapWithoutObjectsList[index]; GameObject mobGameObject = GameObject.Instantiate(mobScriptable.MobPrefab, tileMap.transform.position, Quaternion.identity); mobGameObject.GetComponentInChildren <MobStructure>().TunIntoAMob(mobScriptable, _mapComponent.Tier); } }
public void SpawnNewObjects(GameObject prefab, int amount) { this.ForceInitialization(); for (int i = 0; i < amount; i++) { TileMapComponnent tileMap = _tileMapChildrensList.GetRandomTileMapWihtoutObstacle(new List <EnumSide>() { EnumSide.CENTER }); tileMap.SpawnObject(prefab); if (tileMap is null) { return; } } }