using System.Collections; using System.Collections.Generic; using UnityEngine; namespace UnityStandardAssets.Utility { public class ObjectResetter : MonoBehaviour { private Vector3 originalPosition; private Quaternion originalRotation; private List originalStructure; private Rigidbody Rigidbody; private void Start() { originalStructure = new List(GetComponentsInChildren()); originalPosition = base.transform.position; originalRotation = base.transform.rotation; Rigidbody = GetComponent(); } public void DelayedReset(float delay) { StartCoroutine(ResetCoroutine(delay)); } public IEnumerator ResetCoroutine(float delay) { yield return new WaitForSeconds(delay); Transform[] componentsInChildren = GetComponentsInChildren(); foreach (Transform transform in componentsInChildren) { if (!originalStructure.Contains(transform)) { transform.parent = null; } } base.transform.position = originalPosition; base.transform.rotation = originalRotation; if ((bool)Rigidbody) { Rigidbody.velocity = Vector3.zero; Rigidbody.angularVelocity = Vector3.zero; } SendMessage("Reset"); } } }