RockAttackTrigger.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class RockAttackTrigger : AttackTrigger
  5. {
  6. public string fatName = "¶Ü¼×±ø";
  7. public GameObject rockRoller;
  8. public Vector3 impactRockForcDriction = new Vector3(-1, 0.2f, 0);
  9. public Vector3 impactFatForcDriction = new Vector3(1, 0.2f, 0);
  10. public float fatForceMul = 100f;
  11. public float rockForceMul = 100f;
  12. private float collisionStopDuration = 0.2f;
  13. private float curStopTime = 0f;
  14. public List<BeHitTrigger> attcakFat;
  15. public List<BeHitTrigger> attcakedFat;
  16. public int attackFatNumber = 1;
  17. private int curattackFatNumber = 0;
  18. private int damage;
  19. public int damageMultiple = 10;
  20. protected override void OnTriggerEnter(Collider other)
  21. {
  22. BeHitTrigger hitTrigger = other.GetComponent<BeHitTrigger>();
  23. if (hitTrigger)
  24. {
  25. if (hitTrigger.owner.transform.gameObject.GetComponent<RockRoller>())
  26. {
  27. return;
  28. }
  29. if (hitTrigger.owner.transform.gameObject.GetComponent<Demonic>())
  30. {
  31. if (hitTrigger.owner.transform.gameObject.GetComponent<Demonic>().myName == fatName)
  32. {
  33. attcakFat.Add(hitTrigger);
  34. }
  35. }
  36. base.OnTriggerEnter(other);
  37. }
  38. }
  39. private void OnTriggerStay(Collider other)
  40. {
  41. BeHitTrigger hitTrigger = other.GetComponent<BeHitTrigger>();
  42. if (attcakFat.Contains(hitTrigger))
  43. {
  44. return;
  45. }
  46. if (!hitTrigger)
  47. {
  48. return;
  49. }
  50. if (hitTrigger.owner.transform.gameObject.GetComponent<Demonic>())
  51. {
  52. if (hitTrigger.owner.transform.gameObject.GetComponent<Demonic>().myName == fatName)
  53. {
  54. attcakFat.Add(hitTrigger);
  55. }
  56. }
  57. }
  58. public void Update()
  59. {
  60. if (curStopTime < collisionStopDuration)
  61. {
  62. curStopTime += Time.deltaTime;
  63. attcakFat.Clear();
  64. }
  65. if (attcakFat.Count > 0 && curStopTime > collisionStopDuration && curattackFatNumber < attackFatNumber)
  66. {
  67. foreach (BeHitTrigger hitTrigger in attcakFat)
  68. {
  69. if (attcakedFat.Contains(hitTrigger))
  70. {
  71. continue;
  72. }
  73. GameObject fat = hitTrigger.owner.transform.gameObject;
  74. Demonic fatD = hitTrigger.owner.transform.gameObject.GetComponent<Demonic>();
  75. AttackTrigger at = hitTrigger.owner.transform.gameObject.GetComponentInChildren<RockAttackTrigger>();
  76. if (fatD.state != CharacterState.Attack)
  77. {
  78. HandleFatCollision(fat);
  79. attcakedFat.Add(hitTrigger);
  80. damage = attackMethod.attackInfo.damage * damageMultiple;
  81. hitTrigger.BeHit(damage);
  82. }
  83. if (at)
  84. {
  85. if (at.attackMethod.attackInfo != null)
  86. {
  87. if (at.attackMethod.attackInfo.attackMethod_Type != AttackMethod_Type.Attack_Summon)
  88. {
  89. HandleFatCollision(fat);
  90. attcakedFat.Add(hitTrigger);
  91. damage = attackMethod.attackInfo.damage * damageMultiple;
  92. hitTrigger.BeHit(damage);
  93. }
  94. }
  95. }
  96. if (curattackFatNumber >= attackFatNumber)
  97. {
  98. attcakFat.Clear();
  99. HandleRockCollision(rockRoller);
  100. curattackFatNumber = 0;
  101. curStopTime = 0f;
  102. attcakedFat.Clear();
  103. break;
  104. }
  105. }
  106. }
  107. }
  108. private void HandleRockCollision(GameObject fat)
  109. {
  110. if (rockRoller.GetComponent<RockRoller>().state == CharacterState.Die)
  111. {
  112. return;
  113. }
  114. Rigidbody rockRb = rockRoller.GetComponentInParent<Rigidbody>();
  115. RockRoller Roller = rockRoller.GetComponentInParent<RockRoller>();
  116. Roller.ChangeState(CharacterState.Fall);
  117. rockRb.AddForce(impactRockForcDriction * rockForceMul, ForceMode.Impulse);
  118. }
  119. private void HandleFatCollision(GameObject fat)
  120. {
  121. Rigidbody fatRb = fat.GetComponent<Rigidbody>();
  122. Demonic fater = fat.GetComponent<Demonic>();
  123. fater.GetComponentInChildren<AttributeStatus>().isFly = false;
  124. fater.GetComponentInChildren<AttributeStatus>().hitState = 0;
  125. fater.ChangeState(CharacterState.SpecialStatus_BlowUp);
  126. fatRb.AddForce(impactFatForcDriction * fatForceMul, ForceMode.Impulse);
  127. curattackFatNumber += 1;
  128. }
  129. }