PlayerFoot.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerFoot : MonoBehaviour
  5. {
  6. public bool TrigGround
  7. {
  8. get
  9. {
  10. return trigGroundList.Count > 0;
  11. }
  12. }
  13. public PlayerController player;
  14. public List<GameObject> trigGroundList;
  15. private void Awake()
  16. {
  17. }
  18. private void FixedUpdate()
  19. {
  20. if (!player)
  21. {
  22. return;
  23. }
  24. for (int i = 0; i < trigGroundList.Count; i++)
  25. {
  26. if (trigGroundList[i] == null)
  27. {
  28. trigGroundList.RemoveAt(i);
  29. i--;
  30. }
  31. }
  32. }
  33. private void OnTriggerEnter(Collider other)
  34. {
  35. if (other.CompareTag("Plane") || other.CompareTag("Ground"))
  36. {
  37. trigGroundList.Add(other.gameObject);
  38. }
  39. }
  40. private void OnTriggerExit(Collider other)
  41. {
  42. for (int i = 0; i < trigGroundList.Count; i++)
  43. {
  44. if (trigGroundList[i] == other.gameObject)
  45. {
  46. trigGroundList.RemoveAt(i);
  47. i--;
  48. }
  49. }
  50. }
  51. }