public void Spawn(Vector3 position) { for (int x = 1; x < XSize; x++) { for (int z = 1; z < ZSize; z++) { var position2 = position; position2.x += x; position2.z += z; var tileGameObject = Instantiate(Block, position2, Quaternion.identity, transform); Grid.AddTile(tileGameObject.GetComponent <TileScript>()); tiles.Add(tileGameObject.GetComponent <TileScript>()); } } var middle = position; middle.x += XSize / 2f; middle.z += ZSize / 2f; var tile = tiles.FirstOrDefault(x => x.transform.position.x.Equals(middle.x) && x.transform.position.z.Equals(middle.z)); if (tile != null) { tile.SpawnPickup(Pickup); var tile2 = tiles.FirstOrDefault(x => x.transform.position.x.Equals(middle.x + XSize / 4f) && x.transform.position.z.Equals(middle.z)); if (tile2 != null) { tile2.SpawnPickup(Pickup); } var tile3 = tiles.FirstOrDefault(x => x.transform.position.x.Equals(middle.x - XSize / 4f) && x.transform.position.z.Equals(middle.z)); if (tile3 != null) { tile3.SpawnPickup(Pickup); } } GenerateWalls(position); }