// ----------------------------------------------------------------------------------------- public bool FindTerrainPointUnderMouse(UN_Camera cam, ref Vector3 where) // ----------------------------------------------------------------------------------------- { if (Dbg.Assert(cam != null)) { return(false); } Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (!Physics.Raycast(ray, out hitInfo, 300, _terrainLayerMask)) { return(false); } where = hitInfo.point; return(true); }
// ------------------------------------------------------------------------------------------------ /// <summary> /// Simply returns the 'best' ISelectable under the mouse /// </summary> /// <returns></returns> protected SM_ISelectable CheckForObjectUnderMouse(UN_Camera cam) // ------------------------------------------------------------------------------------------------ { if (Dbg.Assert(cam != null)) { return(null); } Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); if (hits == null) { return(null); } int bestNdx = -1; float bestDst = float.MaxValue; SM_ISelectable bestSelect = null; for (int i = 0; i < hits.Length; i++) { if (hits[i].distance < bestDst) { if (CheckParentsForSelectable(hits[i].transform, ref bestSelect)) { bestNdx = i; } } } if (bestNdx < 0) { return(null); } return(bestSelect); }