| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Platform : MonoBehaviour
- {
- public Rigidbody rb;
- public List<Foot> feet = new List<Foot>();
- public float edgeDistance;
- public bool canDown;
- private void OnTriggerEnter(Collider other)
- {
-
- Foot foot = other.GetComponent<Foot>();
- if (foot != null && foot.transform.parent.gameObject.layer != 8)
- {
- if (Mathf.Abs(foot.transform.position.x - transform.position.x) > edgeDistance)
- {
- return;
- }
- foot.trigGroundList.Add(gameObject);
- feet.Add(foot);
- }
- }
- 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(feet.Exists(i => i == foot))
- {
- feet.Remove(foot);
- }
- }
- }
- private void OnDisable()
- {
- foreach(Foot i in feet)
- {
- if(i.trigGroundList.Exists(a => a == gameObject))
- {
- i.trigGroundList.Remove(gameObject);
- }
- }
- }
- }
|