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);        
    }
}

脚本解析

相关推荐
程序猿阿伟3 小时前
《风格锚点+动态适配:Unity跨设备渲染的核心逻辑》
unity·游戏引擎
倚剑仙13 小时前
Unity-WebGL开发——用IIS(Internet Information Services)部署webGL工程
unity·游戏引擎·webgl
baldr_439620 小时前
关于光照探针的实验和疑问
unity
作孽就得先起床21 小时前
c#调Lua返回个字符串
unity·c#·lua·xlua
井队Tell21 小时前
打造高清3D虚拟世界|零基础学习Unity HDRP高清渲染管线(第十天)
学习·3d·unity
2501_938773991 天前
《资源预加载策略:LayaBox 小游戏引擎资源池架构设计案例分析》
游戏引擎
Python私教2 天前
Unity 游戏开发「工业化级」学习路线 2025 版
学习·unity·游戏引擎
于小汐在咯2 天前
【Unity每日一记】Unity物理引擎:刚体与碰撞体详解
unity·游戏引擎
鱼蛋-Felix2 天前
Unity jar更新不生效怎么解决
unity·游戏引擎·jar