HELP transform.LookAt(ray.direction) not working

My camera casts a ray to the centre of the screen and I have an object that looks at that direction. The problem is, I made it such that certain keys rotate the camera, so there’s a new centre, and the ray from the camera moves too but the object doesn’t look at the new direction

Here’s my code:

void Update (){
int x = Screen.width / 2;
int y = Screen.height / 2;

//Get centre of screen from camera
Ray ray = Camera.main.ScreenPointToRay (new Vector3 (x, y));
Debug.DrawRay (ray.origin, ray.direction * 1000, new Color (1f, 0.922f, 0.016f, 1f));

//Set object direction
object.transform.LookAt (ray.direction);

I’d really appreciate some help with this, thank you!

I found a solution. Instead of looking at ray direction, I got a point from the ray using ray.GetPoint and made the object look at that. It’s working fine now.