Yes, the code version is called vector clamp magnitude. Maybe there is an action for this here or on the ecosystem.
If you want to freeze it on the Y (or any) axis, it’s probably better to use the constraints on the rigidbody component (this can be set by code, too).