public void GenerateMapOnTop(bool isFirst) { //initializing if (transform.parent.gameObject.GetComponentInChildren <EnterController>().isAlreadyActivated) { return; } int offsetLayout = 0; if (isFirst) { offsetLayout = LevelHandler.instance.levelLayoutsCreated.Count - 1; } for (int i = 1; i < LevelHandler.instance.numberOfMapToGenerate; i++) { /// int number = Random.Range(0, upwardPossibilities.Length); CurrentDirection randomDirection = upwardPossibilities[number]; Transform currentParent = LevelHandler.instance.levelLayoutsCreated[i - 1 + offsetLayout].gameObject.transform; Transform currentAnchor = currentParent.GetComponentInChildren <LevelGenerator>().nextLayoutAnchor; BoxCollider2D currentBoxCollider = LevelHandler.instance.levelLayoutsCreated[i - 1 + offsetLayout].GetComponentInChildren <LevelGenerator>().borderCollider; if (LevelHandler.instance.currentDirection == CurrentDirection.UP) { float desiredY = currentAnchor.position.y; float desiredX = currentAnchor.position.x; Debug.Log(currentParent); GameObject newLayout = Instantiate(GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).levelLayOutPrefab, new Vector3(desiredX, desiredY), Quaternion.identity); LevelGenerator newLayoutGenerator = newLayout.GetComponentInChildren <LevelGenerator>(); newLayoutGenerator.Awake(); newLayoutGenerator.pivotAnchor.position = new Vector2(desiredX, desiredY); newLayoutGenerator.levelGeneratorID = +levelGeneratorID + i; newLayoutGenerator.Initialize(); ChangeNextLayoutBackgroundLayers(newLayoutGenerator.backgroundSprites, currentParent.GetComponentInChildren <LevelGenerator>().backgroundSprites.Last().sortingOrder, i); newLayoutGenerator.PostInitialize(); newLayout.name = "LevelLayout-" + (this.levelGeneratorID + 2) + "(" + GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).direction + ")" + GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).type; SendLastGeneratedLevel(newLayoutGenerator, GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).direction); if (i != (int)LevelHandler.instance.numberOfMapToGenerate - LevelHandler.instance.whenToGenerateMoreMaps) { newLayout.GetComponentInChildren <EnterController>().isAlreadyActivated = true; } LevelHandler.instance.LevelAdded(newLayout, newLayoutGenerator, "Up"); } else if (LevelHandler.instance.currentDirection == CurrentDirection.RIGHT) { float desiredY = currentAnchor.position.y; float desiredX = currentAnchor.position.x; GameObject newLayout = Instantiate(GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).levelLayOutPrefab, new Vector3(desiredX, desiredY), Quaternion.identity); LevelGenerator newLayoutGenerator = newLayout.GetComponentInChildren <LevelGenerator>(); newLayoutGenerator.Awake(); newLayoutGenerator.pivotAnchor.position = new Vector2(desiredX, desiredY); newLayoutGenerator.levelGeneratorID = +levelGeneratorID + i; newLayoutGenerator.Initialize(); ChangeNextLayoutBackgroundLayers(newLayoutGenerator.backgroundSprites, currentParent.GetComponentInChildren <LevelGenerator>().backgroundSprites.Last().sortingOrder, i); newLayoutGenerator.PostInitialize(); newLayout.name = "LevelLayout-" + (this.levelGeneratorID + 2) + "(" + GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).direction + ")" + GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).type; SendLastGeneratedLevel(newLayoutGenerator, GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).direction); if (i != (int)LevelHandler.instance.numberOfMapToGenerate - LevelHandler.instance.whenToGenerateMoreMaps) { newLayout.GetComponentInChildren <EnterController>().isAlreadyActivated = true; } LevelHandler.instance.LevelAdded(newLayout, newLayoutGenerator, "Right"); } else if (LevelHandler.instance.currentDirection == CurrentDirection.LEFT) { float desiredY = currentAnchor.position.y; float desiredX = currentAnchor.position.x; GameObject newLayout = Instantiate(GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).levelLayOutPrefab, new Vector3(desiredX, desiredY), Quaternion.identity); LevelGenerator newLayoutGenerator = newLayout.GetComponentInChildren <LevelGenerator>(); newLayoutGenerator.Awake(); newLayoutGenerator.pivotAnchor.position = new Vector2(desiredX, desiredY); newLayoutGenerator.levelGeneratorID = +levelGeneratorID + i; newLayoutGenerator.Initialize(); ChangeNextLayoutBackgroundLayers(newLayoutGenerator.backgroundSprites, currentParent.GetComponentInChildren <LevelGenerator>().backgroundSprites.Last().sortingOrder, i); newLayoutGenerator.PostInitialize(); newLayout.name = "LevelLayout-" + (this.levelGeneratorID + 2) + "(" + GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).direction + ")" + GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).type; SendLastGeneratedLevel(newLayoutGenerator, GameAssets.i.GetDesiredLevelLayout(randomDirection, LevelHandler.instance.levelType).direction); if (i != (int)LevelHandler.instance.numberOfMapToGenerate - LevelHandler.instance.whenToGenerateMoreMaps) { newLayout.GetComponentInChildren <EnterController>().isAlreadyActivated = true; } LevelHandler.instance.LevelAdded(newLayout, newLayoutGenerator, "Left"); } } }