using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; public class Foot : MonoBehaviour { [FoldoutGroup("×é¼þ")] public Rigidbody rb; [FoldoutGroup("×é¼þ")] public MoveCharacter moveCharacter; public bool haveGravity = true; public bool TrigGround { get { return trigGroundList.Count > 0; } } public List trigGroundList; private void Awake() { rb = GetComponentInParent(); moveCharacter = rb.transform.GetComponent(); } private void FixedUpdate() { if (trigGroundList.Count == 0) { if (!haveGravity|| moveCharacter.platformY != 0) { rb.useGravity = true; haveGravity = true; moveCharacter.velocityAddition = 0; moveCharacter.platformY = 0; } } else { Platform platform = null; foreach (var item in trigGroundList) { platform = item.GetComponent(); if (platform!=null) { if (moveCharacter.transform.position.x < platform.right.position.x && moveCharacter.transform.position.x > platform.left.position.x) { break; } } else { break; } } if (platform != null) { if (haveGravity) { if (rb.velocity.y <= 0) { rb.useGravity = false; rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z); moveCharacter.platformY = platform.GetPosY(rb.transform.position); rb.transform.position = new Vector3(rb.transform.position.x, moveCharacter.platformY, rb.transform.position.z); haveGravity = false; } } else { if (platform.rb != null) { moveCharacter.velocityAddition = platform.rb.velocity.x; } moveCharacter.platformY = platform.GetPosY(rb.transform.position); } } else { if (!haveGravity) { rb.useGravity = true; haveGravity = true; } } } } private void OnTriggerEnter(Collider other) { if (other.CompareTag("Ground")|| other.CompareTag("Platform")) { 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--; } } } }