U3D_TobaccoWarehouseISMDTSy.../Assets/Scripts/YL/Loadingoperation.cs

53 lines
1.7 KiB
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Loadingoperation : MonoBehaviour
{
/// <summary>
/// 触发上箱操作
/// </summary>
/// <param name="other"></param>
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Box"))
{
Carinformation car = transform.GetComponent<Carinformation>();
Boxinformation boxinformation = other.gameObject.transform.GetComponent<Boxinformation>();
if (car && boxinformation)
{
boxinformation.ID = car.BoxCode;
}
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<Collider>();
// 确保触发器物体有碰撞体
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("触发器没有碰撞体");
}
}
else
{
Debug.LogError("没有获取到物体");
}
}
}
}