RigidbodyConstraints.FreezePositionY doesn't freeze the position

Here’s my script:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MaxY : MonoBehaviour { public bool isHeightLocked; private RigidbodyConstraints freeze; void Start() { isHeightLocked = new bool(); freeze = new RigidbodyConstraints (); } // Update is called once per frame void Update () { if (Input.GetKeyDown (KeyCode.E)) { isHeightLocked = true; } if (isHeightLocked == true) { freeze = RigidbodyConstraints.FreezePositionY; } } }
Thank you for helping!

GetComponent().constrains = freeze;