IMySelectable DeselectOld() { //deselect older selection IMySelectable oldSel = null; if (selected != null) { oldSel = selected.GetComponent <IMySelectable>(); if (oldSel != null) { oldSel.SetSelected(false); } } return(oldSel); }
void handleClicked(Vector3 CursorScreenPosition) { Debug.Log("clicked"); IMySelectable oldSel = DeselectOld(); RaycastHit hit; //Ray r = cam.ScreenPointToRay(Input.mousePosition); Ray r = cam.ScreenPointToRay(CursorScreenPosition); if (Physics.Raycast(r, out hit, Mathf.Infinity, layerMask)) { GameObject go = hit.collider.gameObject; Debug.LogFormat("GameObject hit: {0}", go.name); IMySelectable sel = go.GetComponent <IMySelectable>(); if (sel == null) { sel = go.GetComponentInParent <IMySelectable>(); if (sel != null) { go = go.transform.parent.gameObject; } else { go = clickedPlane(); if (go == null) { selected = null; return; } sel = go.GetComponent <IMySelectable>(); } } if (sel.SameAs(oldSel)) { selected = null; return; } if (sel != null) { selected = go; sel.SetSelected(true); } } else { Debug.Log("no GameObject hit"); if (clickedPlane() == null) { selected = null; return; } } }