Platform.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 float edgeDistance;
  9. public bool canDown;
  10. private void OnTriggerEnter(Collider other)
  11. {
  12. Foot foot = other.GetComponent<Foot>();
  13. if (foot != null && foot.transform.parent.gameObject.layer != 8)
  14. {
  15. if (Mathf.Abs(foot.transform.position.x - transform.position.x) > edgeDistance)
  16. {
  17. return;
  18. }
  19. foot.trigGroundList.Add(gameObject);
  20. feet.Add(foot);
  21. }
  22. }
  23. private void OnTriggerExit(Collider other)
  24. {
  25. Foot foot = other.GetComponent<Foot>();
  26. if(foot != null && foot.transform.parent.gameObject.layer != 8)
  27. {
  28. if(foot.trigGroundList.Exists(i =>i == gameObject))
  29. {
  30. foot.trigGroundList.Remove(gameObject);
  31. }
  32. if(feet.Exists(i => i == foot))
  33. {
  34. feet.Remove(foot);
  35. }
  36. }
  37. }
  38. private void OnDisable()
  39. {
  40. foreach(Foot i in feet)
  41. {
  42. if(i.trigGroundList.Exists(a => a == gameObject))
  43. {
  44. i.trigGroundList.Remove(gameObject);
  45. }
  46. }
  47. }
  48. }