Freezing character on place when health is 0?

I am creating a 2D game. When the health is 0, I want the player to freeze, so even when we hit the buttons, the character doesn’t move. How can I do it?

You can freeze the Rigidbody position like so:

Rigidbody2D.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY;

And you can remove all the constraints like so:

Rigidbody2D.constraints = RigidbodyConstraints2D.None;

You could Disable Rigidbody and CharacterController.

Put a condition before the code for player movement

If (health > 0)
{
// code that makes the character move
}

Or you could try…
GetComponent= rb
rb.isKinematic=true;

Or you can just disable the script/component handling the movement when the player ‘dies’ (hp < 0).
I think this really is the cleanest way.