using Cysharp.Threading.Tasks;
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Checkposition : MonoBehaviour
{
///
/// 位移的点位
///
public Transform point;
///
/// 位移的速度
///
private float speed = 2f;
public async void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("Box"))
{
if (point.childCount == 0)
{
await MoveObjectToPosition(other.gameObject.transform, point.transform.position, speed);
other.gameObject.transform.SetParent(point);
BoxCollider boxCollider = transform.GetComponent();
if (boxCollider)
{
boxCollider.enabled = false;
}
BoxCollider points = point.GetComponent();
if (points)
{
points.enabled = true;
}
}
}
}
///
/// 箱子做对应的动画
///
///
///
///
///
private async UniTask MoveObjectToPosition(Transform target, Vector3 destination, float speed)
{
float duration = Vector3.Distance(target.position, destination) / speed;
await target.DOMove(destination, duration).AsyncWaitForCompletion();
}
}