I’ve searched around but can’t find the right answer.
I have a gameobject with a rigidbody2D on it. I’ve checked the Freeze Rotation Z so it can’t rotate.
If the player dies I want the freeze rotation not to work anymore.
In another post I found something about using RigidbodyConstraints2D but that doesn’t seem to work.
public RigidbodyConstraints2D playerConstraints;
public int playerLives = 3;
void Update()
{
if (playerLives == 0)
{
playerConstraints = RigidbodyConstraints2D.None;
}
If I make playerLives 0 the Freeze Rotation Z box stays checked.
How can I uncheck the Freeze Rotation Z box with C#?
Try this. Haven’t use it.
1 Like
freezeRotation sounds right (never used it that I recall).
However, with regard to your original post, you never assign it back to the rigidbody, which is why it wasn’t appearing to work. 
1 Like
Already tried this but can’t make it work. I’ve used the bool but nothing happens.
I think methos5k is right, you may not be applying it to the rigidbody in code.
1 Like
It’s working for me. 
Rigidbody2D rb;
void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
rb.freezeRotation = !rb.freezeRotation;
if (Input.GetMouseButtonDown(1))
{
RigidbodyConstraints2D rbc = rb.constraints;
if (rbc == RigidbodyConstraints2D.FreezePosition)
rbc = RigidbodyConstraints2D.FreezeRotation | RigidbodyConstraints2D.FreezePositionY;
else rbc = RigidbodyConstraints2D.FreezePosition;
rb.constraints = rbc;
}
}
1 Like
Added a second example to show some constraints comparisons/assignment. 
(Edited into the post above*).
1 Like
Yes, I forgot to assign it. It’s hard to be a noob but lucky for me you guys are here.
Thanks for helping out. Works great right now.