72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Displaygoods : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 判断物体身上是否有箱子
|
|
/// </summary>
|
|
public GameObject box7;
|
|
/// <summary>
|
|
/// 箱子第一个位置
|
|
/// </summary>
|
|
public Transform Box1;
|
|
public Transform Box2;
|
|
public Transform Box3;
|
|
public float speed = 5f;
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
private async void OnTriggerEnter(Collider other)
|
|
{
|
|
//if (other.gameObject.CompareTag("Car"))
|
|
//{
|
|
// Debug.Log("触发了小车");
|
|
|
|
// if (box7.transform.childCount > 0)
|
|
// {
|
|
// Debug.Log("上向");
|
|
// GameObject box = box7.transform.GetChild(0).gameObject;
|
|
// box.transform.SetParent(null);
|
|
// await Boxmove(box);
|
|
// }
|
|
//}
|
|
}
|
|
public async void OnTriggerStay(Collider other)
|
|
{
|
|
if (other.gameObject.CompareTag("Car"))
|
|
{
|
|
Debug.Log("触发了小车");
|
|
|
|
if (box7.transform.childCount > 0)
|
|
{
|
|
Debug.Log("上向");
|
|
GameObject box = box7.transform.GetChild(0).gameObject;
|
|
box.transform.SetParent(null);
|
|
await Boxmove(other.gameObject,box);
|
|
}
|
|
}
|
|
}
|
|
public async UniTask Boxmove(GameObject car,GameObject box)
|
|
{
|
|
await box.transform.DOMove(Box1.transform.position, (Vector3.Distance(box.transform.position, Box1.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
await box.transform.DOMove(Box2.transform.position, (Vector3.Distance(box.transform.position, Box2.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
await box.transform.DOMove(Box3.transform.position, (Vector3.Distance(box.transform.position, Box3.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
box.transform.SetParent(car.transform);
|
|
Transform point = GameObject.Find("11-32-2").transform;
|
|
await car.transform.DOMove(point.transform.position,(Vector3.Distance(car.transform.position,point.transform.position)/speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
Transform point2 = GameObject.Find("11-33-2").transform;
|
|
await car.transform.DOMove(point2.transform.position, (Vector3.Distance(car.transform.position, point2.transform.position) / speed)).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();
|
|
}
|
|
}
|