I am trying to freeze the x value after the player dies because he just starts to slide even if the movement script is disabled i searched the documents but i couldnt really understand it
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
[SerializeField]private float startingHealth;
public float currentHealth { get; private set; }
private Animator anim;
private bool dead;
public RigidbodyConstraints2D const;
private void Awake()
{
currentHealth = startingHealth;
anim = GetComponent<Animator>();
const = GetComponent<RigidbodyConstraints2D>();
}
public void TakeDamage(float _damage)
{
currentHealth = Mathf.Clamp(currentHealth - _damage, 0, startingHealth);
if(currentHealth > 0)
{
anim.SetTrigger("hurt");
}else{
if(!dead){
anim.SetTrigger("die");
RigidbodyConstraints2D.FreezeAll;
GetComponent<PlayerMovement>().enabled = false;
dead = true;
}
}
}
}