SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
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.

44 lines
1.1 KiB

4 years ago
  1. using UnityEngine;
  2. using System.Collections;
  3. // Cartoon FX - (c) 2015 Jean Moreno
  4. // Automatically destructs an object when it has stopped emitting particles and when they have all disappeared from the screen.
  5. // Check is performed every 0.5 seconds to not query the particle system's state every frame.
  6. // (only deactivates the object if the OnlyDeactivate flag is set, automatically used with CFX Spawn System)
  7. [RequireComponent(typeof(ParticleSystem))]
  8. public class CFX_AutoDestructShuriken : MonoBehaviour
  9. {
  10. // If true, deactivate the object instead of destroying it
  11. public bool OnlyDeactivate;
  12. void OnEnable()
  13. {
  14. StartCoroutine("CheckIfAlive");
  15. }
  16. IEnumerator CheckIfAlive ()
  17. {
  18. ParticleSystem ps = this.GetComponent<ParticleSystem>();
  19. while(true && ps != null)
  20. {
  21. yield return new WaitForSeconds(0.5f);
  22. if(!ps.IsAlive(true))
  23. {
  24. if(OnlyDeactivate)
  25. {
  26. #if UNITY_3_5
  27. this.gameObject.SetActiveRecursively(false);
  28. #else
  29. this.gameObject.SetActive(false);
  30. #endif
  31. }
  32. else
  33. GameObject.Destroy(this.gameObject);
  34. break;
  35. }
  36. }
  37. }
  38. }