private void LoadPuzzle() { //Only allow a new puzzle to be loaded if there isnt already a puzzle. if (!puzzleActive && waveActive) { isPerfect = true; waveFinished = false; //Get the data for a random puzzle from the correct data we initilized earlier Puzzle puzzle = puzzleManager.GetRandomPuzzle(); //Get the amount of blocks needed for the current puzzle int blocksNeededForPuzzle = puzzleLength * width; //Take the blocks from the active wave blocks and put them in active puzzle List <GameObject> tempBlockList = activeWaveBlocks.GetRange(activeWaveBlocks.Count - blocksNeededForPuzzle, blocksNeededForPuzzle); activePuzzleBlocks.AddRange(tempBlockList); activeWaveBlocks.RemoveRange(activeWaveBlocks.Count - blocksNeededForPuzzle, blocksNeededForPuzzle); //Put all the Puzzle cubes into the cube holder for clean hierarchy foreach (GameObject cube in activePuzzleBlocks) { cube.transform.parent = activeCubeHolder; } string[] puzzleInfo = puzzle.puzzleData; //Activate each of the active blocks and turn them into the correct type based on the puzzle data for (int i = 0; i < puzzleInfo.Length; i++) { for (int j = 0; j < puzzleInfo[i].Length; j++) { CubeInfo cubeInfo = activePuzzleBlocks[(i * puzzleInfo[i].Length) + j].GetComponentInChildren <CubeInfo>(); if (cubeInfo != null) { cubeInfo.isActive = true; char tmpChar = puzzleInfo[i][j]; cubeInfo.SetType(int.Parse(tmpChar.ToString())); } else { Debug.Log("Error: No CubeInfo on GameObject"); } } } puzzleActive = true; } }