i am trying to make ragdolls turn on when clicked, but i dont know how to do this. I have ragdoll already but script for turning on ragdoll doesnt works.
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class RagdollEnemy : MonoBehaviour {
// Start is called before the first frame update
void Start()
{
setRigidbodyState(true);
setColliderState(false);
GetComponent<Animator>().enabled = true;
}
public void die()
{
GetComponent<Animator>().enabled = false;
setRigidbodyState(false);
setColliderState(true);
if (gameObject != null)
{
Destroy(gameObject, 3f);
}
}
void setRigidbodyState(bool state)
{
Rigidbody[] rigidbodies = GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody rigidbody in rigidbodies)
{
rigidbody.isKinematic = state;
}
GetComponent<Rigidbody>().isKinematic = !state;
}
void setColliderState(bool state)
{
Collider[] colliders = GetComponentsInChildren<Collider>();
foreach (Collider collider in colliders)
{
collider.enabled = state;
}
GetComponent<Collider>().enabled = !state;
}
}
It may be not proper way but, you can use ragdoll gameobject as another gameobject that set active when you die and set position to player position and set active false your player.I use it like that in my game for my character and also for enemy characters.