Swap game object positions

so im trying to have 2 objects switch places once you click on them. i can get the second object to go to the first spot but the first doesn’t move. I have been staring at this for so long truly any help would be so appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class swap : MonoBehaviour
{
    public GameObject objectOne;
    public GameObject objectTwo;
    public Vector3 pos1;
    public Vector3 pos2;


     void Update()
    {
//click
        if(Input.GetMouseButtonDown(0)) {
            if(objectOne==null){
                RaycastHit hit = CastRay();

               if(hit.collider !=null) {
                if(!hit.collider.CompareTag("book")) {
                    return;
                }
// define objectone as the initial click
                objectOne = hit.collider.gameObject;
                pos1 = new Vector3(objectOne.transform.position.x, objectOne.transform.position.y, objectOne.transform.position.z);
  
               }  
               
            }
            else {
                RaycastHit hit = CastRay();
                
                if(hit.collider !=null){
                    if(!hit.collider.CompareTag("book")) {
                        return;
                    }
// define object2 as the second click
                    objectTwo = hit.collider.gameObject;
                    pos2 = new Vector3(objectTwo.transform.position.x, objectTwo.transform.position.y, objectTwo.transform.position.z);

// switch them
                    objectOne.transform.position = pos2;
                    objectTwo.transform.position = pos1;
//reset
                    objectOne = null;
                    objectTwo = null;
                  
                }
            }           
        }
        

    }
    //raycast
    private RaycastHit CastRay() {
        Vector3 screenMousePosFar = new Vector3(
            Input.mousePosition.x,
            Input.mousePosition.y,
            Camera.main.farClipPlane);
        Vector3 screenMousePosNear = new Vector3(
            Input.mousePosition.x,
            Input.mousePosition.y,
            Camera.main.nearClipPlane);
        Vector3 worldMousePosFar = Camera.main.ScreenToWorldPoint(screenMousePosFar);
        Vector3 worldMousePosNear = Camera.main.ScreenToWorldPoint(screenMousePosNear);
        RaycastHit hit;
        Physics.Raycast(worldMousePosNear, worldMousePosFar - worldMousePosNear, out hit);

        return hit;
    }
}

Nevermind it works exactly how it is meant to, Unity just hates me. I removed the script and restarted unity then pasted it back and it worked.