Transform.position.y fluctuates while `AI.NavMeshAgent.updateUpAxis = false`

I am trying to manipulate a player object in the XZ plane.
I am trying to achieve this by using NavMesh to limit the range of movement.

I don’t want to change the Y axis because the player moves on the XZ plane.

So I am using AI.NavMeshAgent.updateUpAxis = false,Y-axis is fluctuating.

How can I prevent the Y-axis from changing?

Here is the player control script attached to the player object.

using UnityEngine;
using UnityEngine.AI;

public class PlayerController : MonoBehaviour
    public float moveSpeed = 5f;
    private NavMeshAgent agent;

    private void Awake()
        agent = GetComponent<NavMeshAgent>();
        if (agent != null) 
            agent.updateRotation = false;
            agent.updateUpAxis = false;

    private void Update()
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;

    void MovePlayer(Vector3 direction)
        transform.Translate(direction * moveSpeed * Time.deltaTime, Space.World);