unity DoTween DoPath设置物体按照指定轨迹运动

代码控制物体运动轨迹

使用DoTween中的DoPath功能

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

2.准备一个脚本

挂在要移动的物体上

csharp 复制代码
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);        
    }
}

脚本解析

相关推荐
jtymyxmz1 天前
《Unity Shader》7.3 渐变纹理
unity·游戏引擎
ThreePointsHeat2 天前
Unity 关于打包WebGL + jslib录制RenderTexture画面
unity·c#·webgl
胡童嘉2 天前
长沙烈焰鸟网络科技有限公司实习day13日记
功能测试·学习·职场和发展·游戏引擎·cocos2d
y***54882 天前
C++在游戏引擎中的开发
开发语言·c++·游戏引擎
BuHuaX2 天前
Unity_AssetBundle相关
unity·c#·游戏引擎·游戏策划
神码编程2 天前
【Unity】 HTFramework框架(六十八)StringEditor字符串复杂编辑器
unity·编辑器·游戏引擎·htframework
开发游戏的老王2 天前
UE5.6 C++项目升级UE5.7时用Rider加载项目失败的解决办法
ue5·游戏引擎·虚幻·虚幻引擎·rider·ue5.7·target.cs
TO_ZRG2 天前
Unity-iPhone、Unity-Framework target 如何选择、@rpath报错
unity·ios·iphone
平行云2 天前
World Labs & Paraverse:统一3D世界的创造与访问
3d·unity·ai·ue5·aigc·实时云渲染·云xr
jtymyxmz3 天前
《Unity Shader》7.2.3 实践 在切线空间下计算
unity·游戏引擎