Disabling rigidbody constraints in code - Freeze Position, Rotation etc

I'm trying to disable a rigidbody contraint to allow movement in the Y axis using javascript. I found the page showing how to do it in the script help files, but when I tried a very minor variation of it, it doesn't work, and I get an error. Here's my line of code:

transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionY = false;

I also tried it like this:

transform.rigidbody.constraints = RigidbodyConstraints.FreezePosition = false;

and this:

transform.rigidbody.RigidbodyConstraints.FreezePosition = false;

None of those work, so simple question - How do I turn off the position freezing in code?

According to the docs this is how youd freeze the rotation around the x axis:

rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;

I haven't played around with it myself, but I admit it looks a little confusing. The way you set it is using these

I guess to stop rotation along the y axis you'd do

rigidbody.constraints = FreezePositionY

transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionY;

If you want to set multiple options without removing ones that are already set, you can use bitwise math. The docs show this.

If none of these are working, you can always attach a script that forces the rotation to a value each FixedUpdate like this:

var angle : float;//

function Start (){
    angle = transform.rotation.y;
}
function FixedUpdate (){
    transfrom.rotation.y = angle;
}

I got it to work, thanks all

 var player : GameObject;
  


 
 function OnTriggerEnter(other : Collider)
 {
    if(other.gameObject == player)
     {
    	        player.rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
        
    
      }
 }    
     
    
 function OnTriggerExit(other : Collider)
 {
    
     if(other.gameObject == player)
     {
         
          player.rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY; 
         
          
     }
 }

To unfreeze say .constraints = RigidbodyConstraints.None;

@LarryTheBrave. how would I unfreeze the constraint without it affecting all axis? (sorry I am new to this and haven’t learned much of the names for things.)

How do you make it for 2D?