I'm having trouble figuring out how to get an enemy to ragdoll when hp drops below zero. I have a basic code that enables ragdolls when scene starts but I need it enabled after enemy is killed but while they are alive they are rigid. Any help appreciated, thanks!
Side note: fairly new to unity and coding.
public int maxHp = 10;
private int hp;
Component[] bodyparts;
void Start()
{
hp = maxHp;
bodyparts = GetComponentsInChildren();
}
public void Damage(DamageInfo info)
{
if (hp <= 0) return;
hp -= info.damage;
if (hp <= 0) Die();
}
void Die()
{
Destroy(gameObject);
}
}
↧