| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Platform : MonoBehaviour
- {
- public Rigidbody rb;
- public List<Foot> feet = new List<Foot>();
- public bool TrigFeet
- {
- get
- {
- return feet.Count > 0;
- }
- }
- public float edgeDistance;
- public bool canDown;
- public BaGuaTrigger myBaGuaTrigger; //×Ô¼º
- public List<BaGuaTrigger> baGuaTrigger = new List<BaGuaTrigger>(); //Í·¶¥µÄ°ËØÔÅÖ×Ó
- private void OnTriggerEnter(Collider other)
- {
-
- Foot foot = other.GetComponent<Foot>();
- if (foot != null && foot.transform.parent.gameObject.layer != 8 && !foot.notOnGiant)
- {
- if (Mathf.Abs(foot.transform.position.x - transform.position.x) > edgeDistance)
- {
- return;
- }
- if(!foot.trigGroundList.Exists(t=>t == gameObject))
- {
- foot.trigGroundList.Add(gameObject);
- }
- feet.Add(foot);
- if (foot.myBaGuaTrigger != null)
- {
- foot.baGuaTrigger.Add(myBaGuaTrigger);
- baGuaTrigger.Add(foot.myBaGuaTrigger);
- }
- }
- }
- private void OnTriggerExit(Collider other)
- {
- Foot foot = other.GetComponent<Foot>();
- if(foot != null && foot.transform.parent.gameObject.layer != 8)
- {
- if(foot.trigGroundList.Exists(i =>i == gameObject))
- {
- foot.trigGroundList.Remove(gameObject);
- if(foot.baGuaTrigger.Exists(i =>i == myBaGuaTrigger))
- {
- foot.baGuaTrigger.Remove(myBaGuaTrigger);
- }
- }
- if(feet.Exists(i => i == foot))
- {
- feet.Remove(foot);
- if(baGuaTrigger.Exists(i => i == foot.myBaGuaTrigger))
- {
- baGuaTrigger.Remove(foot.myBaGuaTrigger);
- }
- }
- }
- }
- private void OnDisable()
- {
- foreach(Foot i in feet)
- {
- if(i.trigGroundList.Exists(a => a == gameObject))
- {
- i.trigGroundList.Remove(gameObject);
- if(i.baGuaTrigger.Exists(a =>a == myBaGuaTrigger))
- {
- i.baGuaTrigger.Remove(myBaGuaTrigger);
- }
- }
- }
- }
- }
|