//for collision detection void OnCollisionEnter(Collision col) { if (col.gameObject.tag == "Wall") { if (PickupObject.carrying == true) { PickupObject.dropObject(); } } }
void OnTriggerEnter(Collider other) { if (other.gameObject.name == "TempatSampahOr") { PickupObject.dropObject(); waktu.nilai -= nilaiKurang; waktu.sampah -= 1; Destroy(this.gameObject); } else if (other.gameObject.name == "TempatSampahAn") { PickupObject.dropObject(); waktu.nilai -= nilaiKurang; waktu.sampah -= 1; Destroy(this.gameObject); } else if (other.gameObject.name == "TempatSampahBer") { PickupObject.dropObject(); waktu.nilai += nilaiTambah; waktu.sampah -= 1; Destroy(this.gameObject); } }
// Update is called once per frame void Update() { if (Global.currentPuzzle == 3) { // move camera across from puzzle one Vector3 movingBoxCameraPosition = new Vector3(movingBoxCollider.position.x, movingBoxCollider.position.y + 10f, movingBoxCollider.position.z); aboveWarehouseCam.position = movingBoxCameraPosition; Global.monitor.GetComponent <Renderer>().material = aboveWarehouse; // these lights break with realtime lighting //redLight.enabled = true; //blueLight.enabled = true; //greenLight.enabled = true; //yellowLight.enabled = true; redPlane.enabled = true; bluePlane.enabled = true; greenPlane.enabled = true; yellowPlane.enabled = true; puzzleThreeStarted = true; } if (puzzleThreeStarted == true && Global.currentPuzzle == 3) { // RED for (int i = 0; i < redBoxes.Length; i++) { GameObject redBox = redBoxes[i]; Transform redBoxT = redBox.transform; distanceFromRedGoal = Vector3.Distance(redBoxT.position, redGoal.position); // has the box been placed over the goal? if (redInPosition[i] == false && distanceFromRedGoal < goalRange && redPlane.enabled == true && redBox.activeSelf == true) { // set this to true, so that on the next iteration, the next if statement will be entered, and this one will not redInPosition[i] = true; // drop the object if the player is carrying it if (PickupObject.carrying == true) { PickupObject.dropObject(); } } // if this box has been placed over the goal if (redInPosition[i] == true) { // move box toward the end of the tunnel redBox.GetComponent <Transform>().position = Vector3.MoveTowards(redBox.GetComponent <Transform>().position, behindRedGoal.position, step); // see how far it is from reaching the end of the tunnel redDistance = Vector3.Distance(redBox.GetComponent <Transform>().position, behindRedGoal.position); if (redDistance < 0.5) { // disable the cube redBox.SetActive(false); // have to set it to false or else it'll enter this if statement for infiniti and keep incrementing redCount redInPosition[i] = false; // update redCount so we know how many have been placed in the console redCount++; } } } // BLUE for (int i = 0; i < blueBoxes.Length; i++) { GameObject blueBox = blueBoxes[i]; Transform blueBoxT = blueBox.transform; distanceFromBlueGoal = Vector3.Distance(blueBoxT.position, blueGoal.position); if (blueInPosition[i] == false && distanceFromBlueGoal < goalRange && bluePlane.enabled == true && blueBox.activeSelf == true) { blueInPosition[i] = true; if (PickupObject.carrying == true) { PickupObject.dropObject(); } } if (blueInPosition[i] == true) { blueBox.GetComponent <Transform>().position = Vector3.MoveTowards(blueBox.GetComponent <Transform>().position, behindBlueGoal.position, step); blueDistance = Vector3.Distance(blueBox.GetComponent <Transform>().position, behindBlueGoal.position); if (blueDistance < 0.5) { blueBox.SetActive(false); blueInPosition[i] = false; blueCount++; } } } // GREEN for (int i = 0; i < greenBoxes.Length; i++) { GameObject greenBox = greenBoxes[i]; Transform greenBoxT = greenBox.transform; distanceFromGreenGoal = Vector3.Distance(greenBoxT.position, greenGoal.position); if (greenInPosition[i] == false && distanceFromGreenGoal < goalRange && greenPlane.enabled == true && greenBox.activeSelf == true) { greenInPosition[i] = true; if (PickupObject.carrying == true) { PickupObject.dropObject(); } } if (greenInPosition[i] == true) { greenBox.GetComponent <Transform>().position = Vector3.MoveTowards(greenBox.GetComponent <Transform>().position, behindGreenGoal.position, step); greenDistance = Vector3.Distance(greenBox.GetComponent <Transform>().position, behindGreenGoal.position); if (greenDistance < 0.5) { greenBox.SetActive(false); greenInPosition[i] = false; greenCount++; } } } // YELLOW for (int i = 0; i < yellowBoxes.Length; i++) { GameObject yellowBox = yellowBoxes[i]; Transform yellowBoxT = yellowBox.transform; distanceFromYellowGoal = Vector3.Distance(yellowBoxT.position, yellowGoal.position); if (yellowInPosition[i] == false && distanceFromYellowGoal < goalRange && yellowPlane.enabled == true && yellowBox.activeSelf == true) { yellowInPosition[i] = true; if (PickupObject.carrying == true) { PickupObject.dropObject(); } } if (yellowInPosition[i] == true) { yellowBox.GetComponent <Transform>().position = Vector3.MoveTowards(yellowBox.GetComponent <Transform>().position, behindYellowGoal.position, step); yellowDistance = Vector3.Distance(yellowBox.GetComponent <Transform>().position, behindYellowGoal.position); if (yellowDistance < 0.5) { yellowBox.SetActive(false); yellowInPosition[i] = false; yellowCount++; } } } // end of yellow } }