public void SwitchToObjectPlacement(BuildingsManager.BuildingProposal building) { if (currentCursorMode != ControlMode.freeMode) //can only switch to building placement from freemode. { return; } currentCursorMode = ControlMode.objectPlacement; buildingToPlace = building; }
void ObjectPlacementControl() { //RaycastHit hit = CastRay(gridLayer); //Cell cell = Grid.grid.SampleForCell(hit.point); Vector3?hitPos = CastRay(gridLayer); Cell cell = Grid.grid.SampleForCell((Vector3)hitPos); if (!IsCursorOverUI() && cell != null) { buildingToPlace.MovePlan(cell.cellCentre); if (Input.GetMouseButtonDown(0)) { if (buildingToPlace.Construct(cell)) { buildingToPlace = null; SwitchToFreeMode(); return; } } } else //hide building.. { buildingToPlace.MovePlan(outOfViewPosition); } if (Input.GetMouseButtonDown(1)) { buildingToPlace.Cancel(); buildingToPlace = null; SwitchToFreeMode(); } else if (Input.mouseScrollDelta.y > 0.1f || Input.mouseScrollDelta.y < -0.1f) { if (scrollHelperTimer >= timeBetweenScrollRotation) { scrollHelperTimer = 0.0f; buildingToPlace.RotatePlan(Input.mouseScrollDelta.y); } } scrollHelperTimer += Time.deltaTime; }