public void NextLevel() { Debug.Log("Next Level" + currentLevel); currentLevel++; int randomLevel = (int)Mathf.Round(Random.Range(0f, levels.Length - 1)); GameObject level = levels[randomLevel]; if (currentLevel > 1) { offset = latestLevelEnd.transform.position.z; } else { offset = 25f; } foreach (Transform child in level.transform) { GameObject childGo = child.gameObject; GameObject pooled = ObjectPool.instance.GetObjectForType(childGo.tag, false); pooled.transform.position = childGo.transform.position; pooled.transform.position += new Vector3(0f, -6.223f, 0f + offset); if (currentLevel > 0) { } pooled.transform.rotation = childGo.transform.rotation; pooled.transform.parent = this.transform; string t = childGo.tag; string n = childGo.name; if (t == "BoxBlue" || t == "BoxYellow") { //base height is 1.85 we move this by a percentage so low balls remaing almost the same and high balls are much lower than normal //pooled.transform.Translate(Vector3.up * (GameController.instance.heightPercent) ); } if (n == "LevelEnd") { pooled.GetComponent <Renderer>().enabled = false; latestLevelEnd = pooled; } else if (t == "TriggerDoorHolder") { pooled.GetComponentInChildren <TriggerDoorButton>().ResetDoor(); } else { TargetScript targetScript = childGo.GetComponent <TargetScript>(); TargetScript pooledTargetScript = pooled.GetComponent <TargetScript>(); if (targetScript.isMoving) { pooledTargetScript.SetOrigPos(); pooledTargetScript.direction = targetScript.direction; pooledTargetScript.distance = targetScript.distance; pooledTargetScript.speed = targetScript.speed; pooledTargetScript.offsetSeconds = targetScript.offsetSeconds; pooledTargetScript.isMoving = true; } pooledTargetScript.OnShow(childGo.transform.localScale); } } if (currentLevel < 2) { NextLevel(); } }