Вот go:
private void Update()
{
// Get the mouse position
Vector3 mousePos = Input.mousePosition;
// Set the z component of the mouse position to the absolute distance between the camera's z and the object's z.
mousePos.z = Mathf.Abs(Camera.main.transform.position.z - transform.position.z);
// Determine the world position of the mouse pointer
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
// Update the position of the object
transform.position = worldPos;
}