Platform.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Platform : MonoBehaviour
  5. {
  6. public Rigidbody rb;
  7. public List<Foot> feet = new List<Foot>();
  8. public bool TrigFeet
  9. {
  10. get
  11. {
  12. return feet.Count > 0;
  13. }
  14. }
  15. public float edgeDistance;
  16. public bool canDown;
  17. public BaGuaTrigger myBaGuaTrigger; //×Ô¼º
  18. public List<BaGuaTrigger> baGuaTrigger = new List<BaGuaTrigger>(); //Í·¶¥µÄ°ËØÔÅÖ×Ó
  19. private void OnTriggerEnter(Collider other)
  20. {
  21. Foot foot = other.GetComponent<Foot>();
  22. if (foot != null && foot.transform.parent.gameObject.layer != 8 && !foot.notOnGiant)
  23. {
  24. if (Mathf.Abs(foot.transform.position.x - transform.position.x) > edgeDistance)
  25. {
  26. return;
  27. }
  28. if(!foot.trigGroundList.Exists(t=>t == gameObject))
  29. {
  30. foot.trigGroundList.Add(gameObject);
  31. }
  32. feet.Add(foot);
  33. if (foot.myBaGuaTrigger != null)
  34. {
  35. foot.baGuaTrigger.Add(myBaGuaTrigger);
  36. baGuaTrigger.Add(foot.myBaGuaTrigger);
  37. }
  38. }
  39. }
  40. private void OnTriggerExit(Collider other)
  41. {
  42. Foot foot = other.GetComponent<Foot>();
  43. if(foot != null && foot.transform.parent.gameObject.layer != 8)
  44. {
  45. if(foot.trigGroundList.Exists(i =>i == gameObject))
  46. {
  47. foot.trigGroundList.Remove(gameObject);
  48. if(foot.baGuaTrigger.Exists(i =>i == myBaGuaTrigger))
  49. {
  50. foot.baGuaTrigger.Remove(myBaGuaTrigger);
  51. }
  52. }
  53. if(feet.Exists(i => i == foot))
  54. {
  55. feet.Remove(foot);
  56. if(baGuaTrigger.Exists(i => i == foot.myBaGuaTrigger))
  57. {
  58. baGuaTrigger.Remove(foot.myBaGuaTrigger);
  59. }
  60. }
  61. }
  62. }
  63. private void OnDisable()
  64. {
  65. foreach(Foot i in feet)
  66. {
  67. if(i.trigGroundList.Exists(a => a == gameObject))
  68. {
  69. i.trigGroundList.Remove(gameObject);
  70. if(i.baGuaTrigger.Exists(a =>a == myBaGuaTrigger))
  71. {
  72. i.baGuaTrigger.Remove(myBaGuaTrigger);
  73. }
  74. }
  75. }
  76. }
  77. }