public override void _UnhandledInput(InputEvent @event) { if (@event is InputEventMouseButton eventMouseButton) { if (eventMouseButton.ButtonIndex == (int)ButtonList.Left) { var camera = (Camera)GetNode("../CameraGimbal/InnerGimbal/Camera"); var from = camera.ProjectRayOrigin(eventMouseButton.Position); var to = from + camera.ProjectRayNormal(eventMouseButton.Position) * rayLength; var spaceState = GetWorld().DirectSpaceState; var res = spaceState.IntersectRay(from, to, null, 0b10000000000000000000, true, true); Vector3 click_position = new Vector3(0, placement_height_offset, 0); if (res.Contains("position")) { GD.Print(res["position"], res["collider"]); click_position += (Vector3)res["position"]; if (eventMouseButton.IsPressed()) { //GD.Print(click_position); pos1 = click_position / cell_size; } else { pos2 = click_position / cell_size; foreach (int x in Enumerable.Range(0, (int)Math.Abs(pos2.x - pos1.x) + 1)) { foreach (int z in Enumerable.Range(0, (int)Math.Abs(pos2.z - pos1.z) + 1)) { if (pos1.x < pos2.x) { if (pos1.z < pos2.z) { Rpc(nameof(SetCellItem), (int)(x + pos1.x), (int)pos1.y, (int)(z + pos1.z), 26); } else { Rpc(nameof(SetCellItem), (int)(x + pos1.x), (int)pos1.y, (int)(z + pos2.z), 26); } } else { if (pos1.z < pos2.z) { Rpc(nameof(SetCellItem), (int)(x + pos2.x), (int)pos1.y, (int)(z + pos1.z), 26); } else { Rpc(nameof(SetCellItem), (int)(x + pos2.x), (int)pos1.y, (int)(z + pos2.z), 26); } } } } playerlevel.CheckSpaceAndDecide(pos1, pos2); } } } if (eventMouseButton.ButtonIndex == (int)ButtonList.Right && !eventMouseButton.IsPressed()) { var camera = (Camera)GetNode("../CameraGimbal/InnerGimbal/Camera"); var from = camera.ProjectRayOrigin(eventMouseButton.Position); var to = from + camera.ProjectRayNormal(eventMouseButton.Position) * rayLength; var spaceState = GetWorld().DirectSpaceState; var res = spaceState.IntersectRay(from, to, null, 0b10000000000000000000, true, true); Vector3 click_position = new Vector3(0, placement_height_offset, 0); if (res.Contains("position")) { //GD.Print(res["position"], res["collider"]); click_position += (Vector3)res["position"]; } if (((RoadGen)GetNode("./")).AddBuilding(click_position)) { playerlevel.getBuildingLevel().CheckSpace_old(click_position, click_position); } //EmitSignal(nameof(BuildingPlaced), click_position); } } }