Created
June 25, 2017 06:31
-
-
Save tatar1nro/1926c8e72d10f4425f27979d09bde72b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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