// Move the selected piece if one is selected void MoveSelection() { // Check if a piece has been selected if (selectedPiece != null) { // Create a new ray from the camera Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GizmosGL.color = Color.yellow; GizmosGL.AddLine(ray.origin, ray.origin + ray.direction * rayDistance, 0.1f, 0.1f); RaycastHit hit; // Raycast to only hit objects that aren't pieces if (Physics.Raycast(ray, out hit, rayDistance, ~selectionIgnoreLayer)) { hitPoint = hit.point; // Obtain the hit point GizmosGL.color = Color.blue; GizmosGL.AddSphere(hit.point, 0.5f); // Move the piece to position Vector3 piecePos = hit.point + Vector3.up * pieceHeight; selectedPiece.transform.position = piecePos; } if (Input.GetMouseButtonUp(0)) { // Drop the piece to hitpoint Piece piece = selectedPiece.GetComponent <Piece>(); board.DropPiece(piece, hitPoint); // Deselect the piece selectedPiece = null; } } }