You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
561 B

  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. }