SoulFollowEffect.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SoulFollowEffect : MonoBehaviour
  5. {
  6. public float upSpeed;
  7. public bool notFind;
  8. [HideInInspector]
  9. public float angle;
  10. public int soulsNumber;
  11. public float rotateSpeed;
  12. public GameObject soul;
  13. public GameObject soul1;
  14. public ESpirits_Invisible eSpirits;
  15. [HideInInspector]
  16. public List<GameObject> soulsList = new List<GameObject>();
  17. public float distance;
  18. public bool isTransfiguration;
  19. public float KBoomSoulTime;
  20. public SoulBoom soulBoom;
  21. public bool isBooming;
  22. public bool isBoom;
  23. public int boomSoulNumber;
  24. public InvisibleSoulCollector soulCollector;
  25. public float boomScale;
  26. public Transform parent;
  27. private void Awake()
  28. {
  29. if (!isTransfiguration)
  30. {
  31. for (int i = 0; i < eSpirits.followNumber; i++)
  32. {
  33. GameObject newSoul = Instantiate(soul1.gameObject);
  34. newSoul.transform.parent = transform;
  35. newSoul.SetActive(false);
  36. soulsList.Add(newSoul);
  37. }
  38. }
  39. }
  40. private void Update()
  41. {
  42. angle += Time.deltaTime * rotateSpeed;
  43. if (angle >= 360)
  44. {
  45. angle -= 360;
  46. }
  47. transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
  48. if(isBooming)
  49. {
  50. KBoomSoulTime -= Time.deltaTime;
  51. if (KBoomSoulTime <= 0 && KBoomSoulTime > -soulBoom.boomTime)
  52. {
  53. if (!isBoom)
  54. {
  55. isBoom = true;
  56. Boom();
  57. }
  58. }
  59. if (KBoomSoulTime <= -soulBoom.boomTime)
  60. {
  61. for (int i = 0; i < boomSoulNumber; i++)
  62. {
  63. SoulChangeColor(i, false);
  64. }
  65. soulCollector.soulNumbers -= boomSoulNumber;
  66. ShowSouls(soulsNumber - boomSoulNumber);
  67. boomSoulNumber = 0;
  68. isBoom = false;
  69. isBooming = false;
  70. }
  71. }
  72. }
  73. public void DropSoul(int souNumber,bool changeUpSpeed = true)
  74. {
  75. float angle = 360f / souNumber;
  76. for (int i = 0; i < souNumber; i++)
  77. {
  78. GameObject soulObj = PoolManager.Instantiate(soul, transform.position);
  79. float targetRad = angle * i * Mathf.Deg2Rad;
  80. soulObj.transform.position = transform.position +
  81. new Vector3(distance * Mathf.Cos(targetRad), distance * Mathf.Sin(targetRad), 0);
  82. Soul soulScript = soulObj.GetComponent<Soul>();
  83. if (changeUpSpeed)
  84. {
  85. soulScript.Spirits_Invisible_NotFind = notFind;
  86. soulScript.upSpeed = upSpeed;
  87. }
  88. soulScript.Burst(Vector3.zero);
  89. }
  90. }
  91. public void Boom()
  92. {
  93. GameObject boomSoul = Instantiate(soulBoom.gameObject);
  94. boomSoul.transform.position = transform.position;
  95. boomSoul.SetActive(true);
  96. }
  97. public void ShowSouls(int newNumber)
  98. {
  99. if(soulsList.Count < newNumber)
  100. {
  101. GameObject newSoul = Instantiate(soul1.gameObject);
  102. newSoul.transform.parent = transform;
  103. newSoul.SetActive(false);
  104. soulsList.Add(newSoul);
  105. }
  106. if(newNumber == 0)
  107. {
  108. for(int i = 0;i< soulsList.Count; i++)
  109. {
  110. soulsList[i].gameObject.SetActive(false);
  111. }
  112. }
  113. if (newNumber > soulsNumber)
  114. {
  115. for(int i = soulsNumber; i < newNumber; i++)
  116. {
  117. soulsList[i].gameObject.SetActive(true);
  118. }
  119. float angle = 360f / newNumber;
  120. for (int i = 0; i < newNumber; i++)
  121. {
  122. float targetRad = angle * i * Mathf.Deg2Rad;
  123. soulsList[i].transform.localPosition =
  124. new Vector3(distance * Mathf.Cos(targetRad), distance * Mathf.Sin(targetRad), 0);
  125. }
  126. }
  127. if(newNumber < soulsNumber)
  128. {
  129. for(int i = newNumber;i<soulsNumber;i++)
  130. {
  131. soulsList[i].gameObject.SetActive(false);
  132. }
  133. float angle = 360f / newNumber;
  134. for (int i = 0; i < newNumber; i++)
  135. {
  136. float targetRad = angle * i * Mathf.Deg2Rad;
  137. soulsList[i].transform.localPosition =
  138. new Vector3(distance * Mathf.Cos(targetRad), distance * Mathf.Sin(targetRad), 0);
  139. }
  140. }
  141. soulsNumber = newNumber;
  142. }
  143. public void SoulChangeColor(int id,bool isRed)
  144. {
  145. if (isRed)
  146. {
  147. soulsList[id].transform.GetChild(0).gameObject.SetActive(false);
  148. soulsList[id].transform.GetChild(1).gameObject.SetActive(true);
  149. }
  150. else
  151. {
  152. soulsList[id].transform.GetChild(1).gameObject.SetActive(false);
  153. soulsList[id].transform.GetChild(0).gameObject.SetActive(true);
  154. }
  155. }
  156. }