ETFXLoopScript.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 spawnWithoutLight = true;
  11. public bool spawnWithoutSound = 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(spawnWithoutLight = true && effectPlayer.GetComponent<Light>())
  24. {
  25. effectPlayer.GetComponent<Light>().enabled = false;
  26. //Destroy(gameObject.GetComponent<Light>());
  27. }
  28. if(spawnWithoutSound = true && effectPlayer.GetComponent<AudioSource>())
  29. {
  30. effectPlayer.GetComponent<AudioSource>().enabled = false;
  31. //Destroy(gameObject.GetComponent<AudioSource>());
  32. }
  33. yield return new WaitForSeconds(loopTimeLimit);
  34. Destroy (effectPlayer);
  35. PlayEffect();
  36. }
  37. }
  38. }