private void GenerateLevel() { // Place the first platform float[] firstPlatformPositions = Rules.AllOfType("Little Layer"); int randomPick1 = Random.Range(0, firstPlatformPositions.Length); float firstPlatformPosition = firstPlatformPositions[randomPick1]; GameObject firstPlatform = Instantiate(zonePrefab, new Vector3(0, firstPlatformPosition, 0), Quaternion.identity); firstPlatform.AddComponent <LockableZone>().layer = Rules.PlatformName("Little Layer", firstPlatformPosition); firstPlatform.name = "Lockable Zone"; generatedZones.Add(firstPlatform); // Place second lot of platforms. int numberOfPlatformsToGenerate = Random.Range(2, 3); List <float> secondPlatformsPositions = new List <float>(Rules.Options("Little Layer", firstPlatform.GetComponent <Zone>().layer)); Vector3 newPosition; bool thresholdMade = false; for (int i = 0; i < numberOfPlatformsToGenerate; i++) { int randomPick2 = Random.Range(0, secondPlatformsPositions.Count); newPosition.x = firstPlatform.transform.position.x + firstPlatform.transform.lossyScale.x + PlayerMetrics.staticJumpDistance; newPosition.y = secondPlatformsPositions[randomPick2]; newPosition.z = firstPlatform.transform.position.z; GameObject layerTwoPlatform = Instantiate(zonePrefab, newPosition, Quaternion.identity); if (!thresholdMade) { layerTwoPlatform.AddComponent <ThresholdZone>().layer = Rules.PlatformName("Big Layer", secondPlatformsPositions[randomPick2]); layerTwoPlatform.name = "Threshold Zone"; thresholdMade = true; } else { layerTwoPlatform.AddComponent <Zone>().layer = Rules.PlatformName("Big Layer", secondPlatformsPositions[randomPick2]); } secondPlatformsPositions.RemoveAt(randomPick2); generatedZones.Add(layerTwoPlatform); previousPlatforms.Add(layerTwoPlatform); } // Place third layer List <GameObject> thirdLayerPlatforms = ThirdLayer(); // Place the final platform int randomPick4 = Random.Range(0, thirdLayerPlatforms.Count); // Debug.Log("Number of third layer platforms " + thirdLayerPlatforms.Count); // Debug.Log("Random Pick value: " + randomPick4); GameObject thirdLayerPlatformToGenerateFrom = thirdLayerPlatforms[randomPick4]; List <float> fourthPlatformsPositions = new List <float>(Rules.Options("Little Layer", thirdLayerPlatformToGenerateFrom.GetComponent <Zone>().layer)); int randomHeight = Random.Range(0, fourthPlatformsPositions.Count); newPosition.x = thirdLayerPlatformToGenerateFrom.transform.position.x + thirdLayerPlatformToGenerateFrom.transform.lossyScale.x + PlayerMetrics.staticJumpDistance; newPosition.y = fourthPlatformsPositions[randomHeight]; newPosition.z = thirdLayerPlatformToGenerateFrom.transform.position.z; GameObject layerFourPlatform = Instantiate(zonePrefab, newPosition, Quaternion.identity); layerFourPlatform.name = "Reward Zone"; layerFourPlatform.AddComponent <RewardZone>().layer = Rules.PlatformName("Big Layer", fourthPlatformsPositions[randomHeight]); generatedZones.Add(layerFourPlatform); }