// Update is called once per frame void Update() { //Create a ray from the Mouse click position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // drag marker/cone if (alreadyClicked && currMarker != null) { RaycastHit[] hits; hits = Physics.RaycastAll(ray.origin, ray.direction, 1000.0F); for (int i = 0; i < hits.Length; i++) { RaycastHit hit = hits[i]; if (hit.collider.CompareTag("Bone")) { if (currMarker != null) { currMarker.transform.parent.position = hit.point; // hold the y axis Quaternion newRotation = Quaternion.FromToRotation(Vector3.up, hit.normal); currMarker.transform.parent.rotation = Quaternion.Euler(newRotation.eulerAngles.x, currMarker.transform.parent.rotation.eulerAngles.y, newRotation.eulerAngles.z); } break; } } alreadyClicked = false; } // if non-UI element is clicked, get new selection else if (Input.GetMouseButton(0) && vumarkType.value == 0 && mode.value == 0) { RaycastHit enter; if (Physics.Raycast(ray, out enter)) { // handle selection events onMarkerClicked(enter); } alreadyClicked = true; } else { // mouse not down alreadyClicked = false; } // change selection to highlight colors if (currMarker != null) { currMarker.GetComponentInChildren <MeshRenderer>().material.SetColor("_MainColor", Color.red); } // deleting markers if ((Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace))) { if (currMarker != null) { if (currMarker.transform.parent.gameObject == vumarks.front) { vumarks.front = null; } else if (currMarker.transform.parent.gameObject == vumarks.back) { vumarks.back = null; } else if (currMarker.transform.parent.gameObject == vumarks.left) { vumarks.left = null; } else if (currMarker.transform.parent.gameObject == vumarks.right) { vumarks.right = null; } else if (currMarker.transform.parent.gameObject == vumarks.anchor) { vumarks.anchor = null; } vumarks.updateVuMarkText(); Destroy(currMarker); currMarker = null; } } // enter clears selection if (Input.GetKeyDown(KeyCode.Return) || (mode.value == 1) || (mode.value == 2) || vumarkType.value != 0) { Deselect(); } }