using UnityEngine; using DG.Tweening; using Cysharp.Threading.Tasks; public class Movetest : MonoBehaviour { public Transform tarton; public GameObject car; public GameObject car1; public Transform targetPosition; public float speed = 5; private bool isMoving = true; void Start() { car = GameObject.Find("4-1-2"); car1 = GameObject.Find("14-37-2"); tarton = car1.GetComponent(); _ = Planneddisplacement(); } private async UniTask Planneddisplacement() { Transform point = GameObject.Find("8-40-2").transform; await transform.DOMove(point.transform.position, (Vector3.Distance(transform.position, point.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); Transform point2 = GameObject.Find("8-32-2").transform; await transform.DOMove(point2.transform.position, (Vector3.Distance(transform.position, point2.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); Transform point3 = GameObject.Find("13-32-2").transform; await transform.DOMove(point3.transform.position, (Vector3.Distance(transform.position, point3.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); Transform point4 = GameObject.Find("13-37-2").transform; await transform.DOMove(point4.transform.position, (Vector3.Distance(transform.position, point4.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); Transform point5 = GameObject.Find("14-37-2").transform; await transform.DOMove(point5.transform.position, (Vector3.Distance(transform.position, point5.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); await transform.DOMove(point4.transform.position, (Vector3.Distance(transform.position, point4.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); Transform point6 = GameObject.Find("13-39-2").transform; await transform.DOMove(point6.transform.position, (Vector3.Distance(transform.position, point6.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); Transform point7 = GameObject.Find("14-39-2").transform; await transform.DOMove(point7.transform.position, (Vector3.Distance(transform.position, point7.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); await UniTask.Delay(2000); //await transform.DOMove(point6.transform.position, (Vector3.Distance(transform.position, point6.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); //await transform.DOMove(point4.transform.position, (Vector3.Distance(transform.position, point4.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); await transform.DOMove(point6.transform.position, (Vector3.Distance(transform.position, point6.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); await transform.DOMove(point3.transform.position, (Vector3.Distance(transform.position, point3.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); Transform point8 = GameObject.Find("14-32-2").transform; await transform.DOMove(point8.transform.position, (Vector3.Distance(transform.position, point8.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion(); } private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Box")) { Carinformation car = transform.GetComponent(); Boxinformation boxinformation = other.gameObject.transform.GetComponent(); if (car && boxinformation) { boxinformation.ID = car.BoxCode; //Debug.Log(boxinformation.ID); } //Debug.Log("触发了"); float pos = other.transform.position.y + 0.3f; other.transform.DOMoveY(pos, 0.3f).SetEase(Ease.InOutQuad); other.transform.SetParent(transform); if (other.gameObject != null) { // 获取触发器物体的碰撞体 Collider triggerCollider = GetComponent(); // 确保触发器物体有碰撞体 if (triggerCollider != null) { // 计算触发器物体顶部的世界坐标 Vector3 triggerPosition = triggerCollider.bounds.center; Vector3 triggerTop = triggerPosition + Vector3.up * (triggerCollider.bounds.extents.y + -0.2f); // 设置物体的位置 other.transform.position = triggerTop; } else { Debug.LogError("Trigger object does not have a Collider component."); } } else { Debug.LogError("Colliding object is not assigned."); } } } void Update() { } }