Unity_DoTween_Path路径动画的使用

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()
    {
        //路径点数组
        var positions = Pos.Select(u => u.position).ToArray();
        /*
            参数一:路径点 数组
            参数二:完成动画需要 多少秒
            参数三:路径的弧度是曲线还是直线
            参数四:路径模式 Full3D
            参数五:路径点的精密度 数值越大越精密
            参数六:路径线路的颜色

            SetOptions(true) 路径从头回到原点
            SetLookAt(0) 路径物体与路径点保持的夹角 取值范围0-1
         */
        transform.DOPath(positions, 10, PathType.CatmullRom, PathMode.Full3D,50,Color.yellow)
            .SetOptions(true).SetLookAt(0);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

我创建了 14个cube 作为路径点

将上述脚本 挂载到要移动的物体上

我挂载在 相机上了

按住ctrl + 鼠标左键 选中路径点 选中的顺序 就是添加的顺序

选中cube 拖拽到 PathManager脚本的 Pos 数组上就可以了

猜你喜欢

转载自blog.csdn.net/weixin_42137574/article/details/103618810