using System.Collections; using System.Collections.Generic; using UnityEngine; public class Foot : MonoBehaviour { public Rigidbody rb; public bool haveGravity = true; public bool TrigGround { get { return trigGroundList.Count > 0; } } public List trigGroundList; public BaGuaTrigger myBaGuaTrigger; //自己 public List baGuaTrigger = new List(); //脚下的八卦胖子 public bool notOnGiant; private void Update() { rb = GetComponentInParent(); if (trigGroundList.Count == 0) { if (!haveGravity) { rb.useGravity = true; haveGravity = true; rb.GetComponent().velocityAddition = 0; } } else { if (haveGravity) { if (rb.velocity.y < 0) { foreach (GameObject i in trigGroundList) { if (i.layer == 13) { rb.useGravity = false; rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z); haveGravity = false; rb.transform.position = new Vector3 (rb.transform.position.x, i.transform.position.y, rb.transform.position.z); break; } } } } else { Platform platform = trigGroundList[0].GetComponent(); if (platform != null && platform.rb != null) { rb.GetComponent().velocityAddition = platform.rb.velocity.x; } } } } private void FixedUpdate() { for (int i = 0; i < trigGroundList.Count; i++) { if (trigGroundList[i] == null) { trigGroundList.RemoveAt(i); i--; } } } private void OnTriggerEnter(Collider other) { if (other.CompareTag("Plane")) { if (notOnGiant) { Platform platform = other.gameObject.GetComponent(); if (platform) { return; } } if (!trigGroundList.Exists(t => t == other.gameObject)) { trigGroundList.Add(other.gameObject); } } } private void OnTriggerExit(Collider other) { for (int i = 0; i < trigGroundList.Count; i++) { if (trigGroundList[i] == other.gameObject) { trigGroundList.RemoveAt(i); i--; } } } }