139 lines
6.1 KiB
C#
139 lines
6.1 KiB
C#
|
||
using UnityEngine;
|
||
using DG.Tweening;
|
||
using Cysharp.Threading.Tasks;
|
||
using System.Drawing;
|
||
using UnityEngine.UIElements;
|
||
|
||
public class Movetest : MonoBehaviour
|
||
{
|
||
|
||
public Transform tarton;
|
||
public GameObject car;
|
||
public GameObject car1;
|
||
public Transform targetPosition;
|
||
public float speed = 5;
|
||
private bool isMoving = false;
|
||
|
||
void Start()
|
||
{
|
||
|
||
car = GameObject.Find("4-1-2");
|
||
|
||
car1 = GameObject.Find("14-37-2");
|
||
tarton = car1.GetComponent<Transform>();
|
||
|
||
//MoveTo(tarton);
|
||
//Sequence mySequence = DOTween.Sequence();
|
||
//mySequence.Append(transform.DOMove(car.transform.position, 5).SetEase(Ease.InOutQuad)).Append(transform.DOMove(car1.transform.position, 5)).SetEase(Ease.InOutQuad).Append(transform.DOMove(car.transform.position, 5).OnComplete(() =>
|
||
//{
|
||
|
||
//}));
|
||
_ = Planneddisplacement(14, 37, 2);
|
||
}
|
||
|
||
private async UniTask Planneddisplacement(int column, int line, int layer)
|
||
{
|
||
|
||
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<Carinformation>();
|
||
Boxinformation boxinformation = other.gameObject.transform.GetComponent<Boxinformation>();
|
||
if (car && boxinformation)
|
||
{
|
||
boxinformation.ID = car.BoxCode;
|
||
Debug.Log(boxinformation.ID);
|
||
}
|
||
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
other.transform.SetParent(transform);
|
||
if (other.gameObject != null)
|
||
{
|
||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
||
Collider triggerCollider = GetComponent<Collider>();
|
||
|
||
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
||
if (triggerCollider != null)
|
||
{
|
||
// <20><><EFBFBD>㴥<EFBFBD><E3B4A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嶥<EFBFBD><E5B6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Vector3 triggerPosition = triggerCollider.bounds.center;
|
||
Vector3 triggerTop = triggerPosition + Vector3.up * (triggerCollider.bounds.extents.y + -0.2f);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||
other.transform.position = triggerTop;
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("Trigger object does not have a Collider component.");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("Colliding object is not assigned.");
|
||
}
|
||
}
|
||
}
|
||
public void MoveTo(Transform target)
|
||
{
|
||
targetPosition = target;
|
||
isMoving = true;
|
||
}
|
||
void Update()
|
||
{
|
||
//if (tarton)
|
||
//{
|
||
// agent.SetDestination(tarton.transform.position);
|
||
//}
|
||
if (isMoving)
|
||
{
|
||
MoveToTarget();
|
||
}
|
||
}
|
||
private void MoveToTarget()
|
||
{
|
||
if (targetPosition == null) return;
|
||
Debug.Log("ִ<><D6B4><EFBFBD><EFBFBD>");
|
||
Vector3 direction = (targetPosition.position - transform.position).normalized;
|
||
|
||
|
||
|
||
|
||
float step = speed * Time.deltaTime;
|
||
transform.position = Vector3.MoveTowards(transform.position, targetPosition.position, step);
|
||
|
||
if (Vector3.Distance(transform.position, targetPosition.position) < 0.1f)
|
||
{
|
||
transform.DOMove(car.transform.position, 2);
|
||
isMoving = false;
|
||
|
||
}
|
||
}
|
||
}
|