how to restrict rotation to 1 axis

Hi I’m making a simple fps game for my history class and I made a system that if the player enters in the field of view of an enemy he will rotate to look at the player however I would like to limit hit rotation only in the y axis so he only rotates in one axis however what happens now is that when you are far away he is straight up and when your close he is lying on the ground

Here is my code until now:

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

public class EnemyAi : MonoBehaviour
{

    bool detected;
    GameObject target;
    public Transform enemy;

    private var rotation;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (detected)
        {
            rotation = enemy.LookAt(target.transform);

            Mathf.Clamp(rotation, 0f, 0f);
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Player")
        {
            detected = true;
            target = other.gameObject;
        }
    }
}

Have you tried rigidbody freeze rotation?

176476-11.png