private void updateTriggers() { int j = 0; foreach (GameObject trigger in sortBoxTriggers) { // Debug.Log("Update trigger " + j); SortBoxTriggerScript sbts = trigger.GetComponent <SortBoxTriggerScript>(); sbts.correctValue = sortingAlgorithm.ArrayToSort[j]; if (solved) { sortBoxTriggers[j].GetComponent <SortBoxTriggerScript>().isFinal = true; Debug.Log("Solved " + j); } else if (j == sortBoxTriggers.Length - sortingAlgorithm.CurrentStep()) { sortBoxTriggers[j].GetComponent <SortBoxTriggerScript>().isFinal = true; } j++; if (sbts.isFinal) { sbts.DoneInIteration = true; } else { sbts.DoneInIteration = false; } } if (!isShowingGeneralInstructions) { instructionWall.GetComponentInChildren <TextMeshPro>().text = sortingAlgorithm.GetInstruction(); } }
IEnumerator createTriggersAndBoxes() { solved = false; GetComponent <ResizeTable>().updateTableSize(boxesToSort); sortBoxes = new GameObject[boxesToSort]; sortBoxTriggers = new GameObject[boxesToSort]; sortingAlgorithm = new BubbleSort(); sortingAlgorithm.ArrayToSort = createRandomArray(); int j = 0; foreach (int i in sortingAlgorithm.ArrayToSort) { GameObject box = Instantiate(sortBox, boxSpawnPoint.transform); SortBoxScript sortBoxScript = box.GetComponent <SortBoxScript>(); if (sortBoxScript) { sortBoxScript.SetNumbersVisible(isNumbersVisible); sortBoxScript.SetGrabbable(j == leftIndex || j == rightIndex); } GameObject boxTrigger = Instantiate(sortBoxTrigger, boxSpawnPoint.transform); boxTrigger.transform.localPosition += new Vector3(0, 0, j * boxTrigger.transform.localScale.z * 1.1f); //boxTrigger.GetComponent<SortBoxTriggerScript>().correctValue = i; //Debug.Log("Does this run on restart?"); box.transform.localPosition += new Vector3(0, 0, j * boxTrigger.transform.localScale.z * 1.1f); boxTrigger.GetComponent <SortBoxHandler>().SetActive(true); //TODO: This stuff should probably be placed on SortBoxScript instead. box.GetComponent <SortBoxScript>().value = i; foreach (TextMeshPro tmPro in box.GetComponentsInChildren <TextMeshPro>()) { tmPro.text = i.ToString(); } sortBoxes[j] = box; sortBoxTriggers[j] = boxTrigger; j++; yield return(null); } triggerLeft = sortBoxTriggers[leftIndex].GetComponent <SortBoxTriggerScript>(); triggerRight = sortBoxTriggers[rightIndex].GetComponent <SortBoxTriggerScript>(); if (triggerLeft && triggerRight) { boxLeft = triggerLeft.GetObjectInTrigger().GetComponent <SortBoxScript>(); boxRight = triggerRight.GetObjectInTrigger().GetComponent <SortBoxScript>(); } //sortBoxTriggers[j - sortingAlgorithm.CurrentStep() - 1].GetComponent<SortBoxTriggerScript>().isFinal = true; updateTriggers(); if (!isShowingGeneralInstructions) { instructionWall.GetComponentInChildren <TextMeshPro>().text = sortingAlgorithm.GetInstruction(); } tableExist = true; }