DelayDestroy.cs 468 B

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. using System.Collections;
  3. public class DelayDestroy : MonoBehaviour {
  4. public float delay = 5f;
  5. protected float startTime;
  6. // Use this for initialization
  7. protected void Start ()
  8. {
  9. startTime = GameTime.time;
  10. }
  11. protected void OnEnable()
  12. {
  13. startTime = GameTime.time;
  14. }
  15. // Update is called once per frame
  16. protected virtual void FixedUpdate ()
  17. {
  18. if(GameTime.time - startTime > delay)
  19. {
  20. Destroy(this.gameObject);
  21. }
  22. }
  23. }