How do i make object look at another object only on Y-Axis?

Hello

I have this script

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position),rotationSpeed * Time.deltaTime);

but I only want the object to rotate on the Y-Axis can someone help?

Calculate the direction vector and zero its y component - this makes the direction strictly horizontal:

  var dir = target.position - transform.position;
  dir.y = 0; // kill height differences
  transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), rotationSpeed * Time.deltaTime);