68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Transportbox : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 物体位移到指定位置
|
|
/// </summary>
|
|
public Transform transportbox;
|
|
/// <summary>
|
|
/// 位移箱子速度
|
|
/// </summary>
|
|
public float speed = 5f;
|
|
/// <summary>
|
|
/// 提升机
|
|
/// </summary>
|
|
public GameObject Uptrans;
|
|
/// <summary>
|
|
/// 需要位移的点位
|
|
/// </summary>
|
|
public Transform point;
|
|
/// <summary>
|
|
/// 记住提升机初始位置
|
|
/// </summary>
|
|
public Transform pos;
|
|
/// <summary>
|
|
/// 箱子的位置
|
|
/// </summary>
|
|
public Transform boxpos;
|
|
void Start()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
private async void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.CompareTag("Box"))
|
|
{
|
|
await Makeprogress(other.gameObject, Uptrans);
|
|
}
|
|
}
|
|
|
|
private async UniTask Makeprogress(GameObject box, GameObject hoister)
|
|
{
|
|
await hoister.transform.DOMove(point.transform.position, (Vector3.Distance(hoister.transform.position, transportbox.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
box.gameObject.transform.position = new Vector3(box.transform.position.x, box.transform.position.y + 0.8f, box.transform.position.z);
|
|
box.gameObject.transform.SetParent(null);
|
|
await Moveup(box.gameObject, hoister);
|
|
}
|
|
private async UniTask Moveup(GameObject point, GameObject upmachine)
|
|
{
|
|
await point.transform.DOMove(transportbox.transform.position, (Vector3.Distance(point.transform.position, transportbox.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
point.transform.SetParent(upmachine.transform);
|
|
await upmachine.transform.DOMove(pos.transform.position, (Vector3.Distance(upmachine.transform.position, pos.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
point.transform.SetParent(null);
|
|
await point.transform.DOMove(boxpos.transform.position,(Vector3.Distance(point.transform.position,boxpos.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
}
|
|
}
|