I did not like fixing this problem. My game takes place on a spherical planet and the enemy must follow the player and then rotate in the direction of the target and according to the spherical shape of the planet
void Update()
{
Vector3 dir = (player.position - enemy.position).normalized;
Vector3 worldDir = (planet.position - enemy.position).normalized;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
float angleX = Mathf.Atan(worldDir.x) * Mathf.Rad2Deg;
enemy.position = Vector3.Slerp(enemy.position - planet.position, player.position - planet.position, Time.deltaTime * 0.4f); //il nemico segue il player sullla superficie sferica
//Quaternion dirWorld = Quaternion.FromToRotation(enemy.transform.up, dir) * enemy.transform.rotation * Quaternion.FromToRotation(enemy.transform.up, worldDir) * enemy.transform.rotation; //rotazione in base al mondo sferico
var dir1 = Quaternion.Euler(0, angle, 0) * Vector3.up;
dir1 = Quaternion.Euler(-angleX, 0,0) * dir1;
enemy.rotation = Quaternion.FromToRotation(enemy.transform.up, dir1)*enemy.rotation;
}