SingleScreenBorder.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SingleScreenBorder : MonoBehaviour
  5. {
  6. public ScreenCrash sc;
  7. [Header("是否可生效")]
  8. public bool canAffect;
  9. [Header("挂载的对象是哪个边界")]
  10. public bool isUp;
  11. public bool isDown;
  12. public bool isLeft;
  13. public bool isRight;
  14. private void JudgeCanRebound(Enemy ene)
  15. {
  16. if (!ene.isBeBlownUp)
  17. {
  18. return;
  19. }
  20. Vector3 vel = ene.rb.velocity;
  21. if (isLeft && vel.x < 0 || isRight && vel.x > 0)
  22. {
  23. Vector3 force = sc.forceX;
  24. if (!isLeft)
  25. {
  26. force.x = -force.x;
  27. }
  28. ene.isBeReboundedX = true;
  29. ene.BeHit(ene.wallDamage);
  30. return;
  31. }
  32. if (isUp && vel.y > 0 || isDown && vel.y < 0)
  33. {
  34. ene.isBeReboundedY = true;
  35. ene.BeHit(ene.wallDamage);
  36. return;
  37. }
  38. return;
  39. }
  40. private void OnTriggerEnter(Collider other)
  41. {
  42. if (canAffect && other.gameObject.layer == 8)
  43. {
  44. Enemy e = other.GetComponentInParent<Enemy>();
  45. JudgeCanRebound(e);
  46. }
  47. }
  48. }