Skip to content

Instantly share code, notes, and snippets.

@tatar1nro
Created June 25, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tatar1nro/1926c8e72d10f4425f27979d09bde72b to your computer and use it in GitHub Desktop.
Save tatar1nro/1926c8e72d10f4425f27979d09bde72b to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationRecorderRagdollHelper : MonoBehaviour
{
[SerializeField] private Rigidbody _rigidBody;
[SerializeField] private Vector3 _applyingForce;
[SerializeField] private float _startingDelay;
[SerializeField] public bool _recordAnimation;
void Start ()
{
StartCoroutine ( Handle () );
}
private IEnumerator Handle ()
{
yield return new WaitForSeconds ( _startingDelay );
Animator animator = GetComponent<Animator> ();
if ( animator != null )
{
animator.enabled = false;
}
Rigidbody[] rBodies = GetComponentsInChildren<Rigidbody> ();
for ( int i = 0; i < rBodies.Length; ++i )
{
rBodies [ i ].isKinematic = false;
}
BoxCollider[] bColliders = GetComponentsInChildren<BoxCollider> ();
for ( int i = 0; i < bColliders.Length; ++i )
{
bColliders [ i ].isTrigger = false;
}
CapsuleCollider[] cColliders = GetComponentsInChildren<CapsuleCollider> ();
for ( int i = 0; i < cColliders.Length; ++i )
{
cColliders [ i ].isTrigger = false;
}
SphereCollider[] sColliders = GetComponentsInChildren<SphereCollider> ();
for ( int i = 0; i < sColliders.Length; ++i )
{
sColliders [ i ].isTrigger = false;
}
_rigidBody.AddForce ( _applyingForce, mode: ForceMode.VelocityChange );
if ( _recordAnimation )
{
gameObject.AddComponent<AnimationRecorder> ().StartRecording ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment