how to freeze all rotations and x position from the code?,How freeze all rotations and x position from code?

I just want to freeze all rotations and x position from the code

i.constraints = RigidbodyConstraints2D.FreezePositionX;
i.constraints = RigidbodyConstraints2D.FreezeRotation;

“i” is a rigidbody2d object
,i just want to freeze all rotations and x position from code
i.constraints = RigidbodyConstraints2D.FreezePositionX;
i.constraints = RigidbodyConstraints2D.FreezeRotation;
“i” is a rigidbody2d object

Sounds like this scenario!

I think you were overwriting the constraints.

Try this:

i.constraints = RigidbodyConstraints2D.FreezePositionX & RigidbodyConstraints2D.FreezeRotation;

or this

i.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;