I try to move my 3D object in the game but it only on the X & Z axis, can someone help me with that

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class DragObject : MonoBehaviour

{

private Vector3 mOffset;
private float mZCoord;

void OnMouseDown()

{

    mZCoord = Camera.main.WorldToScreenPoint(

        gameObject.transform.position).z;
    mOffset = gameObject.transform.position - GetMouseAsWorldPoint();

}

private Vector3 GetMouseAsWorldPoint()

{

    Vector3 mousePoint = Input.mousePosition;

    mousePoint.z = mZCoord;

    return Camera.main.ScreenToWorldPoint(mousePoint);

}

void OnMouseDrag()

{

    transform.position = GetMouseAsWorldPoint() + mOffset;

}

}

Good day.

Add him a rigidboy component,

alt text

Freeze Position