private void InitializeNewStep() { // lock all triggers and reset trigger state to incorrect foreach (GameObject trigger in triggers) { R_TriggerScript t = trigger.GetComponent <R_TriggerScript>(); t.IsLocked = true; if (index == 1 && t.State != ETriggerState.correct) { t.State = ETriggerState.incorrect; } } if (isCompleted) { Completed(); return; } trigger1 = triggers[index - 1]; trigger2 = triggers[index]; trigger1script = trigger1.GetComponent <R_TriggerScript>(); trigger2script = trigger2.GetComponent <R_TriggerScript>(); box1 = boxes[index - 1]; box2 = boxes[index]; box1script = box1.GetComponent <R_BoxScript>(); box2script = box2.GetComponent <R_BoxScript>(); trigger1script.IsLocked = false; trigger2script.IsLocked = false; boxesChecked = false; }
// 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; } R_BoxScript leftBox = leftObject.GetComponent <R_BoxScript>(); R_BoxScript rightBox = rightObject.GetComponent <R_BoxScript>(); if (!(leftBox && rightBox)) { return; } if (leftBox.Value < rightBox.Value) { leftObject.transform.localScale = new Vector3(0.06f, 0.06f, 0.06f); //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.06f, 0.06f, 0.06f); } } }
public void InitializeStep(int index = 1) { trigger1 = triggers[index - 1]; trigger2 = triggers[index]; trigger1script = trigger1.GetComponent <R_TriggerScript>(); trigger2script = trigger2.GetComponent <R_TriggerScript>(); box1 = currentState[index - 1]; box2 = currentState[index]; box1script = box1.GetComponent <R_BoxScript>(); box2script = box2.GetComponent <R_BoxScript>(); int count = 0; foreach (GameObject trigger in triggers) { trigger.GetComponent <R_TriggerScript>().IsLocked = true; if (count > iteration) { triggers[count].GetComponent <R_TriggerScript>().State = ETriggerState.inactive; } count++; } trigger1script.IsLocked = false; trigger2script.IsLocked = false; trigger2script.State = ETriggerState.pivot; boxesChecked = false; hasSwapInStep = false; if (box1script.Value > box2script.Value) { hasSwapInStep = true; } Debug.Log("hasSwapInStep: " + hasSwapInStep); }
void OnCollisionEnter(Collision col) { GameObject obj = col.gameObject; if (obj.CompareTag("SortBox")) { R_BoxScript script = obj.GetComponent <R_BoxScript>(); R_Manager manager = FindObjectOfType <R_Manager>(); // Find correct trigger to spawn to. If not found, spawn at default location (SpawnPoint). int i = manager.Algorithm.GetBoxIndex(script.gameObject); Vector3 spawn = SpawnPoint.transform.position; if (i >= 0 && manager.Algorithm.GetTriggerFromIndex(i).GetComponent <R_TriggerScript>().IsEmpty()) { spawn = manager.Algorithm.GetTriggerFromIndex(i).transform.position; } script.Move(spawn); // Remove velocity and to hinder box from falling off table again immediately Rigidbody boxrb = script.gameObject.GetComponent <Rigidbody>(); if (boxrb) { boxrb.velocity = Vector3.zero; boxrb.rotation = Quaternion.identity; } } }
public void InitializeStep() { if (!hasPivot) { PivotStep(); return; } if (leftIndex <= right) { leftTrigger = triggers[leftIndex]; leftTriggerScript = leftTrigger.GetComponent <R_TriggerScript>(); leftBox = boxes[leftIndex]; leftBoxScript = leftBox.GetComponent <R_BoxScript>(); } rightTrigger = triggers[rightIndex]; pivotTrigger = triggers[pivotIndex]; rightTriggerScript = rightTrigger.GetComponent <R_TriggerScript>(); pivotTriggerScript = pivotTrigger.GetComponent <R_TriggerScript>(); rightBox = boxes[rightIndex]; pivotBox = boxes[pivotIndex]; rightBoxScript = rightBox.GetComponent <R_BoxScript>(); pivotBoxScript = pivotBox.GetComponent <R_BoxScript>(); SetTriggersInactive(); if (!leftSideFound && !(leftIndex > right)) { leftTriggerScript.IsLocked = false; pivotTriggerScript.IsLocked = false; leftTriggerScript.State = ETriggerState.incorrect; pivotTriggerScript.State = ETriggerState.pivot; } else if (leftSideFound && rightSideFound) { pivotTriggerScript.IsLocked = true; leftTriggerScript.IsLocked = false; rightTriggerScript.IsLocked = false; pivotTriggerScript.State = ETriggerState.pivot; leftTriggerScript.State = ETriggerState.intermediate; rightTriggerScript.State = ETriggerState.intermediate; } else { rightTriggerScript.IsLocked = false; pivotTriggerScript.IsLocked = false; if (leftIndex <= right) { leftTriggerScript.State = ETriggerState.intermediate; } pivotTriggerScript.State = ETriggerState.pivot; rightTriggerScript.State = ETriggerState.incorrect; } boxesChecked = false; }
private void InitializeBoxesAndTriggers(int numOfBoxes, List <int> listToSort = null) { foreach (GameObject box in boxes) { Destroy(box); } foreach (GameObject trigger in triggers) { Destroy(trigger); } // Clear values in lists in case they are already filled (e.g. when resetting) boxes.Clear(); triggers.Clear(); // Initialize boxes and triggers for (int i = 0; i < numOfBoxes; ++i) { // Create box with a random value GameObject box = Instantiate(SortBox, Table.transform.Find("BoxSpawn")); R_BoxScript boxScript = box.GetComponent <R_BoxScript>(); if (listToSort == null) { boxScript.Value = UnityEngine.Random.Range(1, BoxValueMax + 1); } else { boxScript.Value = listToSort[i]; } boxScript.Visibility = NumberVisibility; boxScript.IsSnapping = BoxSnapping; // Create trigger GameObject trigger = Instantiate(SortBoxTrigger, Table.transform.Find("BoxSpawn")); trigger.GetComponent <R_TriggerScript>().SetHasTriggerColour(ShowTriggerColours); // Move trigger and the associated box to the correct position on the table // They are moved from the base position (BoxSpawn GameObject) based on the triggers' size trigger.transform.localPosition += new Vector3(0, 0, i * trigger.transform.localScale.z * 1.1f); box.transform.localPosition += new Vector3(0, 0, i * trigger.transform.localScale.z * 1.1f); // Add box and trigger to respective lists boxes.Add(box); triggers.Add(trigger); //SetHighlighting(EnableHighlighting); } }
public void OnTriggerEnter(Collider other) { if (other.CompareTag("SortBox")) { boxesInTrigger.Add(other.gameObject); IsLocked = isLocked; State = state; R_BoxScript box = other.GetComponent <R_BoxScript>(); box.RegisterSpawnPosition(gameObject.transform.position); if (!box.IsGrabbed) { box.Snap(); } } }