Platform.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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)
  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. }
  34. }
  35. private void OnTriggerExit(Collider other)
  36. {
  37. Foot foot = other.GetComponent<Foot>();
  38. if(foot != null && foot.transform.parent.gameObject.layer != 8)
  39. {
  40. if(foot.trigGroundList.Exists(i =>i == gameObject))
  41. {
  42. foot.trigGroundList.Remove(gameObject);
  43. }
  44. if(feet.Exists(i => i == foot))
  45. {
  46. feet.Remove(foot);
  47. }
  48. }
  49. }
  50. private void OnDisable()
  51. {
  52. foreach(Foot i in feet)
  53. {
  54. if(i.trigGroundList.Exists(a => a == gameObject))
  55. {
  56. i.trigGroundList.Remove(gameObject);
  57. }
  58. }
  59. }
  60. }