using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DG.Tweening;
using UnityEngine;
public class PathManager : MonoBehaviour
{
public Transform[] Pos;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void 路径移动()
{
//路径点数组
var positions = Pos.Select(u => u.position).ToArray();
/*
参数一:路径点 数组
参数二:完成动画需要 多少秒
参数三:路径的弧度是曲线还是直线
参数四:路径模式 Full3D
参数五:路径点的精密度 数值越大越精密
参数六:路径线路的颜色
SetOptions(true) 路径从头回到原点
SetLookAt(0) 路径物体与路径点保持的夹角 取值范围0-1
SetLoops(-1) -1无限循环 循环的次数
SetEase(Ease.Linear) 匀速线性运动
*/
transform.DOPath(positions, 10, PathType.Linear, PathMode.Full3D, 100, Color.yellow)
.SetOptions(true).SetLookAt(0).SetLoops(-1).SetEase(Ease.Linear);
}
}
我创建了 14个cube 作为路径点
![](https://img-blog.csdnimg.cn/201912191751005.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjEzNzU3NA==,size_16,color_FFFFFF,t_70)
将上述脚本 挂载到要移动的物体上
我挂载在 相机上了
![](https://img-blog.csdnimg.cn/20191219175232904.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjEzNzU3NA==,size_16,color_FFFFFF,t_70)
按住ctrl + 鼠标左键 选中路径点 选中的顺序 就是添加的顺序
选中cube 拖拽到 PathManager脚本的 Pos 数组上就可以了