SoulBoom.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SoulBoom : MonoBehaviour
  5. {
  6. [HideInInspector]
  7. public float time;
  8. public float boomTime;
  9. [HideInInspector]
  10. public bool isBoom;
  11. public AttackInfo attackInfo;
  12. public float destroyTime;
  13. public List<MoveCharacter> characters = new List<MoveCharacter>();
  14. public bool isTransfiguration;
  15. public float soulUnstableTime;
  16. public Transform parent;
  17. private void Start()
  18. {
  19. parent = GameObject.Find("SoulBoom").transform;
  20. }
  21. private void Update()
  22. {
  23. time += Time.deltaTime;
  24. if (time >= boomTime)
  25. {
  26. if (time < boomTime + 0.1)
  27. {
  28. GetComponent<Collider>().enabled = true;
  29. }
  30. else
  31. {
  32. if (!isBoom)
  33. {
  34. transform.parent = parent;
  35. for (int i = 0; i < characters.Count; i++)
  36. {
  37. if (characters[i].state == CharacterState.Die)
  38. {
  39. continue;
  40. }
  41. PlayerController playerController =
  42. characters[i].GetComponent<PlayerController>();
  43. if (playerController != null && playerController.isBaseBtnOut)
  44. {
  45. continue;
  46. }
  47. Vector3 target;
  48. Vector3 pos1 = characters[i].transform.position;
  49. Vector3 pos2 = transform.position;
  50. target = (pos1 - pos2).normalized;
  51. characters[i].BeHit
  52. (attackInfo.damage, target * attackInfo.force, true, attackInfo.repelValue);
  53. }
  54. isBoom = true;
  55. }
  56. }
  57. }
  58. if (time >= destroyTime)
  59. {
  60. gameObject.SetActive(false);
  61. }
  62. }
  63. private void OnTriggerEnter(Collider other)
  64. {
  65. BeHitTrigger beHitTrigger = other.GetComponent<BeHitTrigger>();
  66. if (beHitTrigger != null
  67. && (other.transform.parent.parent.parent.gameObject.layer == 6
  68. || other.transform.parent.parent.parent.gameObject.layer == 7))
  69. {
  70. MoveCharacter character = other.GetComponentInParent<MoveCharacter>();
  71. if (character.rb == null)
  72. {
  73. character = character.transform.parent.GetComponent<MoveCharacter>();
  74. }
  75. if (!characters.Exists(t => t == character))
  76. {
  77. characters.Add(character);
  78. }
  79. }
  80. //if (!isTransfiguration && beHitTrigger != null
  81. // && (other.transform.parent.parent.parent.gameObject.layer == 6
  82. // || other.transform.parent.parent.parent.gameObject.layer == 7))
  83. //{
  84. // print(111);
  85. // MoveCharacter character = other.GetComponentInParent<MoveCharacter>();
  86. // if (character.rb == null)
  87. // {
  88. // character = character.transform.parent.GetComponent<MoveCharacter>();
  89. // }
  90. // if (!characters.Exists(t => t == character))
  91. // {
  92. // characters.Add(character);
  93. // }
  94. //}
  95. //if (isTransfiguration && beHitTrigger != null && other.transform.parent.parent.parent.gameObject.layer == 8)
  96. //{
  97. // MoveCharacter character = other.GetComponentInParent<MoveCharacter>();
  98. // if (!characters.Exists(t => t == character))
  99. // {
  100. // characters.Add(character);
  101. // }
  102. //}
  103. }
  104. private void OnTriggerExit(Collider other)
  105. {
  106. BeHitTrigger beHitTrigger = other.GetComponent<BeHitTrigger>();
  107. if (beHitTrigger != null
  108. && (other.transform.parent.parent.parent.gameObject.layer == 6
  109. || other.transform.parent.parent.parent.gameObject.layer == 7))
  110. {
  111. MoveCharacter character = other.GetComponentInParent<MoveCharacter>();
  112. if (characters.Exists(t => t == character))
  113. {
  114. characters.Remove(character);
  115. }
  116. }
  117. //if (!isTransfiguration && beHitTrigger != null
  118. // && (other.transform.parent.parent.parent.gameObject.layer == 6
  119. // || other.transform.parent.parent.parent.gameObject.layer == 7))
  120. //{
  121. // MoveCharacter character = other.GetComponentInParent<MoveCharacter>();
  122. // if (characters.Exists(t => t == character))
  123. // {
  124. // characters.Remove(character);
  125. // }
  126. //}
  127. //if (isTransfiguration && beHitTrigger != null && other.transform.parent.parent.parent.gameObject.layer == 8)
  128. //{
  129. // MoveCharacter character = other.GetComponentInParent<MoveCharacter>();
  130. // if (characters.Exists(t => t == character))
  131. // {
  132. // characters.Remove(character);
  133. // }
  134. //}
  135. }
  136. }