// cast a ray in the specified direction and call any SampleController.TriggerEnter found private void Scan(Vector3 direction) { // Draw a debug ray for the scanner line Debug.DrawRay(transform.position, direction); Ray origin = new Ray(transform.position, direction); // Get a Raycast Hit (and save it for the hinge position) if (Physics.Raycast(origin, out hit, 100)) { SelectionController sampleHit = hit.collider.gameObject.GetComponent <SelectionController>(); // If something is already indicated, check if it's different from currently indicated if (indicated != null && !indicated.Equals(sampleHit)) { indicated.TriggerLeave(); } // Debug.Log("There is " + hit.collider.gameObject.name + " detected"); indicated = sampleHit; if (indicated != null) { indicated.TriggerEnter(hit.collider.gameObject); } } else if (indicated) { indicated.TriggerLeave(); indicated = null; } }
// activate reticles at all the touchpoints private void TouchStart(ControlData controlData) { TouchData[] touches = controlData.touches; ScreenData screen = controlData.screen; // deactivate the reticles foreach (GameObject retic in reticles) { retic.SetActive(false); } // If there's an item indicated, move the indicated to selected status if (indicated != null) { selected = indicated; Debug.Log("selected indicated: " + indicated.gameObject.name); if (hinge) { hinge.transform.position = hit.point; hinge.connectedBody = selected.gameObject.GetComponent <Rigidbody>(); } } foreach (TouchData touch in touches) { int touchIndex = Int32.Parse(touch.identifier); if (touchIndex < reticles.Length) { // Activate the reticle reticles[touchIndex].SetActive(true); // Move the reticle to the indicated relative touch location reticles[touchIndex].transform.localPosition = TouchToScreen(touch, screen); } } }