mycj_demo/mycj/Assets/Script/npcMove.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2024-12-02 09:37:47 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class npcMove : MonoBehaviour
{
public List<Transform> path=new List<Transform>();
public float moveNeedTimer;
public void Init(List<Transform> path,float moveNeedTimer)
{
this.path = path;
this.moveNeedTimer = moveNeedTimer;
StartCoroutine(move());
}
IEnumerator move()
{
// <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ Vector3 <20><><EFBFBD><EFBFBD>
Vector3[] pathPoints = new Vector3[this.path.Count];
for (int i = 0; i < path.Count; i++)
{
pathPoints[i] = path[i].position;
}
// ʹ<><CAB9> DOPath <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>
yield return this.transform.DOPath(pathPoints, moveNeedTimer, PathType.Linear)
.SetOptions(false) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
.SetEase(Ease.InOutSine)
.WaitForCompletion();
//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>յ<EFBFBD>
PlayerInfo.instance.ChangeHp(-1);
Destroy(this.gameObject);
}
}