35 lines
786 B
C#
35 lines
786 B
C#
using Sirenix.OdinInspector;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class RagdollComponent : MonoBehaviour
|
|
{
|
|
[Button]
|
|
public void Ragdoll()
|
|
{
|
|
StartCoroutine(RagdollCoroutine());
|
|
}
|
|
|
|
// Needs to be coroutine, because if we modify all rigidbodies at the same time,
|
|
// unity play mode crashed in VR
|
|
IEnumerator RagdollCoroutine()
|
|
{
|
|
var animators = GetComponentsInChildren<Animator>();
|
|
|
|
foreach (var a in animators)
|
|
{
|
|
a.enabled = false;
|
|
}
|
|
|
|
var rigidBodies = GetComponentsInChildren<Rigidbody>();
|
|
|
|
foreach (var rb in rigidBodies)
|
|
{
|
|
rb.isKinematic = false;
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|