how to freeze game unity code example

Example: freeze object unity

public Rigidbody2D rb;

void Start()
{
	//Freeze Rotation on X Axis
	rb.constraints = RigidbodyConstraints2D.FreezeRotationX;
    //Freeze Rotation on Y Axis
    rb.constraints = RigidbodyConstraints2D.FreezeRotationY;
    //Freeze Rotation on Z Axis
    rb.constraints = RigidbodyConstraints2D.FreezeRotationZ;

	//Freeze Position on X Axis
	rb.constraints = RigidbodyConstraints2D.FreezePositionX;
    //Freeze Position on Y Axis
	rb.constraints = RigidbodyConstraints2D.FreezePositionY;
    //Freeze Position on Z Axis
	rb.constraints = RigidbodyConstraints2D.FreezePositionZ;
  
    //Freeze All Axis (Rotation & Position)
    rb.constraints = RigidbodyConstraints2D.FreezeAll;
    //UnFreeze All Axis (Rotation & Position)
    rb.constraints = RigidbodyConstraints2D.None;
}