DestroySelf.cs 856 B

1234567891011121314151617181920212223242526272829
  1. namespace UnityEngine.XR.Interaction.Toolkit.Samples.StarterAssets
  2. {
  3. /// <summary>
  4. /// Destroys the GameObject it is attached to after a specified amount of time.
  5. /// </summary>
  6. public class DestroySelf : MonoBehaviour
  7. {
  8. [SerializeField]
  9. [Tooltip("The amount of time, in seconds, to wait after Start before destroying the GameObject.")]
  10. float m_Lifetime = 0.25f;
  11. /// <summary>
  12. /// The amount of time, in seconds, to wait after Start before destroying the GameObject.
  13. /// </summary>
  14. public float lifetime
  15. {
  16. get => m_Lifetime;
  17. set => m_Lifetime = value;
  18. }
  19. /// <summary>
  20. /// See <see cref="MonoBehaviour"/>.
  21. /// </summary>
  22. void Start()
  23. {
  24. Destroy(gameObject, m_Lifetime);
  25. }
  26. }
  27. }