TimedObjectDestructor.cs 561 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using UnityEngine;
  3. namespace UnityStandardAssets.Utility
  4. {
  5. public class TimedObjectDestructor : MonoBehaviour
  6. {
  7. [SerializeField] private float m_TimeOut = 1.0f;
  8. [SerializeField] private bool m_DetachChildren = false;
  9. private void Awake()
  10. {
  11. Invoke("DestroyNow", m_TimeOut);
  12. }
  13. private void DestroyNow()
  14. {
  15. if (m_DetachChildren)
  16. {
  17. transform.DetachChildren();
  18. }
  19. DestroyObject(gameObject);
  20. }
  21. }
  22. }