void FreeModeControl() { if (!IsCursorOverUI() && //Effectively prevents attempting to selectobjects/cast ray if over a UI element Input.GetMouseButtonDown(0)) { //Cast a ray and check if it hits something we handle. RaycastHit hit = CastRay(freeModeSelectables); if (hit.collider != null) { //print ("hit: " + hit.collider.gameObject.name); Building clickedbuilding; if (hit.collider.gameObject.TryGetComponent <Building>(out clickedbuilding)) { clickedbuilding.ShowDetailsOnViewer(); } } } else if (!IsCursorOverUI() && Input.GetMouseButtonDown(2)) { //save the last mouse position (which will be used to calculate rotation angles) lastMiddleClickLocation = Input.mousePosition; //compute rotation origin RaycastHit hit = cameraControl.CastRay(gridLayer | ground, maxRayCastDistance); if (hit.collider != null) { rotationOrigin = hit.point; } else { print("Rotating about Grid centre"); //test rotationOrigin = Grid.grid.gameObject.transform.position; } } else if (Input.GetMouseButton(2)) { CameraRotate(rotationOrigin); } else if (Input.GetMouseButtonDown(1)) { rightClickHoldTime = 0.0f; lastRightClickLocation = Input.mousePosition; } else if (Input.GetMouseButton(1)) { rightClickHoldTime += Time.deltaTime; if (rightClickHoldTime >= rightClickHoldToPanTime) { CameraDrag(); } } else { //here we can safely allow zooming or move camera by moving mouse to screen edge. CameraScrollZoom(); CameraEdgeMove(); } }