Constraining Y axis in Drag and Drop?

Greetings, I’ve been using a script I found online. I’ve been bashing my head off it in an attempt to alter the code to constrain the movement on the Y axis but have been having no luck. Would anybody be able to lend me a hand on this? Code below…

using UnityEngine;
 
using System.Collections;
 
[RequireComponent(typeof(BoxCollider))]
 
public class MovePoint2 : MonoBehaviour
{
    private Vector3 screenPoint;
    private Vector3 offset;
 
    void OnMouseDown() 
    { 
       screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
 
       offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
 
       Screen.showCursor = false;
    }
 
    void OnMouseDrag() 
    { 
       Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
 
       Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
 
       transform.position = curPosition;
 
    }
 
    void OnMouseUp()
    {
       Screen.showCursor = true;
    }
}

Declare a float to store the mouse’s y position. In your onmousedown function, store the y position. Then just reassign the y position every frame in the onmousedrag function.

using UnityEngine;
 
using System.Collections;
 
[RequireComponent(typeof(BoxCollider))]
 
public class MovePoint2 : MonoBehaviour
{
    private Vector3 screenPoint;
    private Vector3 offset;

private float _lockedYPosition;
void OnMouseDown()
{

       screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
       _lockedYPosition = screenPoint.y;
       offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
 
       Screen.showCursor = false;
    }
 
    void OnMouseDrag() 
    { 

       Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
 
       Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
       curPosition = _lockedYPosition;
       transform.position = curPosition;
 
    }
 
    void OnMouseUp()
    {
       Screen.showCursor = true;
    }
}