AttackTrigger.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Base.Common;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class AttackTrigger : MonoBehaviour
  6. {
  7. public Character owner;
  8. public List<BeHitTrigger> trigedObjs;
  9. public int damage;
  10. public Vector3 force;
  11. public bool changeHurt;
  12. public float repelValue;
  13. public int offsetY = 1;
  14. public float hitRate = 1;
  15. private bool isInVain; //»÷ÖйâÇò£¬¹¥»÷ÎÞЧ
  16. private void Awake()
  17. {
  18. owner = GetComponentInParent<Character>();
  19. }
  20. private void OnTriggerEnter(Collider other)
  21. {
  22. if (isInVain)
  23. {
  24. return;
  25. }
  26. Photosphere photosphere = other.GetComponentInParent<Photosphere>();
  27. if (photosphere && Util.CheckCanHit(owner.tag, "Player"))
  28. {
  29. isInVain = true;
  30. photosphere.Reflex(owner.beHitTrigger, damage);
  31. return;
  32. }
  33. BeHitTrigger hitTrigger = other.GetComponent<BeHitTrigger>();
  34. if (hitTrigger != null)
  35. {
  36. bool triged = false;
  37. for (int i = 0; i < trigedObjs.Count; i++)
  38. {
  39. if (trigedObjs[i] == hitTrigger)
  40. {
  41. triged = true;
  42. break;
  43. }
  44. }
  45. if (!triged)
  46. {
  47. trigedObjs.Add(hitTrigger);
  48. }
  49. }
  50. }
  51. private void OnEnable()
  52. {
  53. trigedObjs.Clear();
  54. }
  55. private void OnDisable()
  56. {
  57. if (isInVain)
  58. {
  59. isInVain = false;
  60. }
  61. else
  62. {
  63. for (int i = 0; i < trigedObjs.Count; i++)
  64. {
  65. if (trigedObjs[i] && Util.CheckCanHit(owner.tag, trigedObjs[i].owner.tag) && !trigedObjs[i].owner.isDie)
  66. {
  67. trigedObjs[i].BeHit(damage, force, changeHurt, repelValue);
  68. if (owner.GetComponent<Demonic>())
  69. {
  70. trigedObjs[i].attackerID = owner.GetComponent<Demonic>().id;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }