ETFXLoopScript.cs 922 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace EpicToonFX
  4. {
  5. public class ETFXLoopScript : MonoBehaviour
  6. {
  7. public GameObject chosenEffect;
  8. public float loopTimeLimit = 2.0f;
  9. [Header("Spawn without")]
  10. public bool disableLights = true;
  11. public bool disableSound = true;
  12. void Start ()
  13. {
  14. PlayEffect();
  15. }
  16. public void PlayEffect()
  17. {
  18. StartCoroutine("EffectLoop");
  19. }
  20. IEnumerator EffectLoop()
  21. {
  22. GameObject effectPlayer = (GameObject) Instantiate(chosenEffect, transform.position, transform.rotation);
  23. if (disableLights && effectPlayer.GetComponent<Light>())
  24. {
  25. effectPlayer.GetComponent<Light>().enabled = false;
  26. }
  27. if (disableSound && effectPlayer.GetComponent<AudioSource>())
  28. {
  29. effectPlayer.GetComponent<AudioSource>().enabled = false;
  30. }
  31. yield return new WaitForSeconds(loopTimeLimit);
  32. Destroy (effectPlayer);
  33. PlayEffect();
  34. }
  35. }
  36. }