// Update is called once per frame void Update() { //Check we're not clicking on a UI element if (Input.GetMouseButtonDown(0)) { foreach (RectTransform RT in _canvas.GetComponentsInChildren <RectTransform>(false)) { if (RT.name == "RR") { break; //because RR covers the whole screen } if (RT.name.StartsWith("BuilderGUI")) { continue; //So does the canvas but we just want to skip this } Vector3[] worldCorners = new Vector3[4]; RT.GetWorldCorners(worldCorners); if (Input.mousePosition.x >= worldCorners[0].x && Input.mousePosition.x < worldCorners[2].x && Input.mousePosition.y >= worldCorners[0].y && Input.mousePosition.y < worldCorners[2].y) { _mouseDownOnUI = true; break; } } } if (Input.GetMouseButtonUp(0)) { //Check we didn't drag the mouse onto the terrain if (Dragging == false && _mouseDownOnUI == false) { //If you've clicked on a UI element then you didn't mean to click the terrain foreach (RectTransform RT in _canvas.GetComponentsInChildren <RectTransform>(false)) { if (RT.name == "RR") { break; //because RR covers the whole screen } if (RT.name.StartsWith("BuilderGUI")) { continue; } Vector3[] worldCorners = new Vector3[4]; RT.GetWorldCorners(worldCorners); if (Input.mousePosition.x >= worldCorners[0].x && Input.mousePosition.x < worldCorners[2].x && Input.mousePosition.y >= worldCorners[0].y && Input.mousePosition.y < worldCorners[2].y) { return; } } RaycastHit Hit; Ray R = BuilderCam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(R, out Hit)) { if (Hit.collider.name.Contains("Terrain")) { if (Toolbox.SelectedTool == "RoadSectn")// && BezCurr.CtrlPts.Count - BezCtrlPt.Current.CtrlPtId ==2) { AddSection(Hit.point); } if (Toolbox.SelectedTool == "Scenery") { AddScenery(Hit.point); } Game.current.Dirty = true; } if (Hit.collider.name.Contains("RoadSeg")) { if (Toolbox.SelectedTool == "StartingLine") { int SegNo = int.Parse(Hit.collider.name.Substring(7)); //InsertMarker(SegNo) PlaceStartingLine(SegNo); } if (Toolbox.SelectedTool == "Scenery") { AddScenery(Hit.point); } Game.current.Dirty = true; } } } //Draw the line Bez.DrawLine(); //GetComponent<BuilderCamController>().FreezeTilt = false; _mouseDownOnUI = false; Dragging = false; } }