public void moveConveyor(float movement, XRayMachine xRayMachine) { if (bagInspectState == BagHandler.BagInspectState.NOTHING) { float xrayScanRight = xRayMachine.scanRight; float xrayScanLeft = xRayMachine.scanLeft; List <GameObject> bags = Misc.FindShallowStartsWith("Bag_"); foreach (GameObject bag in bags) { BagProperties bagProperties = bag.GetComponent <BagProperties>(); if (bagProperties.isOnConveyor) { float bagNewXPos = bag.transform.position.x + movement; GameObject triggerCube = bagProperties.contentsTriggerCube; float centerOfTriggerCube = bag.transform.position.x + triggerCube.transform.localPosition.x; float bagRightmostPos = centerOfTriggerCube + triggerCube.transform.localScale.x / 2f; float bagLeftmostPos = centerOfTriggerCube - triggerCube.transform.localScale.x / 2f; if (movement > 0 && bagRightmostPos < xrayScanLeft && bagRightmostPos + movement >= xrayScanLeft) { bagProperties.showItems(true); } else if (movement > 0 && bagLeftmostPos < xrayScanRight && bagLeftmostPos + movement >= xrayScanRight) { bagProperties.showItems(false); } else if (movement < 0 && bagLeftmostPos >= xrayScanRight && bagLeftmostPos + movement < xrayScanRight) { bagProperties.showItems(true); } else if (movement < 0 && bagRightmostPos >= xrayScanLeft && bagRightmostPos + movement < xrayScanLeft) { bagProperties.showItems(false); } if (movement > 0 && bagNewXPos > xRayMachine.xPointOfNoReturn) { bagProperties.bagFinished(); } else { if (bagProperties.bagDefinition.person.showingPassport && bagProperties.bagDefinition.person.currentX >= xRayMachine.xPointOfNoBackingBags) { bagProperties.bagDefinition.person.showPassport(false); } if (movement > 0 || (movement < 0 && bag.transform.position.x < xRayMachine.xPointOfNoBackingBags)) { bag.transform.position = new Vector3(bag.transform.position.x + movement, bag.transform.position.y, bag.transform.position.z); } } } } PubSub.publish("belt_movement", movement); } }