using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; public class Loadingoperation : MonoBehaviour { /// /// 触发上箱操作 /// /// private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Box")) { Debug.Log("触发器上箱操作"); if (transform.childCount == 0) { Carinformation car = transform.GetComponent(); Boxinformation boxinformation = other.gameObject.transform.GetComponent(); //if (car && boxinformation) //{ // boxinformation.ID = car.BoxCode; //} //float pos = other.transform.position.y + 0.5f; other.transform.DOMoveY(other.transform.position.y + 0.42f, 0.3f).SetEase(Ease.InOutQuad).OnComplete(() => { if (other.gameObject != null) { // 获取触发器物体的碰撞体 Collider triggerCollider = GetComponent(); // 确保触发器物体有碰撞体 if (triggerCollider != null) { // 计算触发器物体顶部的世界坐标 Vector3 triggerPosition = triggerCollider.bounds.center; Vector3 triggerTop = triggerPosition + Vector3.up * (triggerCollider.bounds.extents.y); // 设置物体的位置 other.transform.position = triggerTop; other.gameObject.transform.SetParent(transform); } else { Debug.LogError("触发器没有碰撞体"); } } else { Debug.LogError("没有获取到物体"); } }); } } } }