instantiateEffectCaller.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class instantiateEffectCaller : MonoBehaviour
  5. {
  6. [System.NonSerialized]
  7. public bool fired = false;
  8. float timer;
  9. public float timeLimit;
  10. [System.Serializable]
  11. public class chainEffect
  12. {
  13. [System.NonSerialized]
  14. public bool isPlayed = false;
  15. public float activateTimer;
  16. public GameObject Effect;
  17. public Transform effectLocator;
  18. }
  19. public chainEffect[] chainEffectList;
  20. void Start()
  21. {
  22. // print(chainEffectList.Length);
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. timer += Time.deltaTime;
  28. CheckTimer();
  29. }
  30. void CheckTimer()
  31. {
  32. for (int i = 0; i < chainEffectList.Length; i++)
  33. {
  34. if (timer >= chainEffectList[i].activateTimer && chainEffectList[i].isPlayed == false)
  35. {
  36. Instantiate(chainEffectList[i].Effect, chainEffectList[i].effectLocator.transform.position, chainEffectList[i].effectLocator.transform.rotation);
  37. chainEffectList[i].isPlayed = true;
  38. }
  39. }
  40. if (timer >= timeLimit)
  41. {
  42. fired = false;
  43. ResetTimers();
  44. }
  45. }
  46. public void ResetTimers()
  47. {
  48. for (int i = 0; i < chainEffectList.Length; i++)
  49. {
  50. chainEffectList[i].isPlayed = false;
  51. }
  52. timer = 0;
  53. }
  54. }