void Update() { if (Input.GetButtonUp("Instruction")) { showGeneralInstructions(); Debug.Log("Pressing Button"); } if (Input.GetButtonUp("Restart")) { reloadTable(boxesToSort); } // TODO Handle with events instead of checking every frame if (triggerLeft && triggerRight && boxLeft && boxRight) { if (boxLeft && boxRight && boxLeft.IsGrabbed() && boxRight.IsGrabbed() && !triggerLeft.HasObject() && !triggerRight.HasObject()) { bothPickedUp = true; } if (bothPickedUp && (triggerLeft.isCorrect || triggerRight.isFinal) && triggerLeft.HasObject() && triggerRight.HasObject()) { bothPickedUp = false; triggerLeft.DoneInIteration = true; if (triggerRight.isFinal) { triggerRight.DoneInIteration = true; } boxLeft.SetGrabbable(false); boxRight.SetGrabbable(false); ++leftIndex; // TODO Create method in algorithm to get next index (this only works with bubble sort) ++rightIndex; // TODO Create method in algorithm to get next index (this only works with bubble sort) if (triggerRight.isFinal || rightIndex >= sortBoxTriggers.Length) { leftIndex = 0; // TODO Create method in algorithm to get next index (this only works with bubble sort) rightIndex = 1; // TODO Create method in algorithm to get next index (this only works with bubble sort) } triggerLeft = sortBoxTriggers[leftIndex].GetComponent <SortBoxTriggerScript>(); triggerRight = sortBoxTriggers[rightIndex].GetComponent <SortBoxTriggerScript>(); if (triggerLeft && triggerRight) { boxLeft = triggerLeft.GetLastObjectInTrigger().GetComponent <SortBoxScript>(); boxRight = triggerRight.GetLastObjectInTrigger().GetComponent <SortBoxScript>(); } else { boxLeft = null; boxRight = null; Debug.LogError("A BOX WAS NOT FOUND!"); } if (boxLeft && boxRight) { boxLeft.SetGrabbable(true); boxRight.SetGrabbable(true); } } } }
// Update is called once per frame void Update() { // TODO If you pick up two boxes, then drop one, the other should be scaled to normal size if (leftInteract && rightInteract) { GameObject leftObject = leftInteract.GetGrabbedObject(); GameObject rightObject = rightInteract.GetGrabbedObject(); if (!(leftObject && rightObject)) { return; } SortBoxScript leftBox = leftObject.GetComponent <SortBoxScript>(); SortBoxScript rightBox = rightObject.GetComponent <SortBoxScript>(); if (!(leftBox && rightBox)) { return; } if (leftBox.value < rightBox.value) { leftObject.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); //rightObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); } else if (leftBox.value > rightBox.value) { //leftObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); rightObject.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); } } }
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; }