unity DoTween DoPath设置物体按照指定轨迹运动
代码控制物体运动轨迹
- 1.在场景中设置一些路径点
- 2.准备一个脚本
使用DoTween中的DoPath功能

1.在场景中设置一些路径点

2.准备一个脚本
挂在要移动的物体上
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AirShitTweenTest : MonoBehaviour
{public List<Vector3> PathVector3s1 ;public Transform PathParent1;private void Awake(){InitPathPoint();StandbyAnim();}public void InitPathPoint(){for (int i = 0; i < PathParent1.childCount; i++) { PathVector3s1.Add(PathParent1.GetChild(i).position); }}public void StandbyAnim(){Tween tween = transform.DOPath(PathVector3s1.ToArray(), 10f, PathType.CatmullRom, PathMode.Full3D, 10, Color.green).SetLookAt(0.01f).SetOptions(true);tween.SetLoops(-1,LoopType.Incremental);tween.SetEase(Ease.Linear); }
}
脚本解析

