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

脚本解析

相关推荐
RReality9 小时前
【Unity Shader URP】序列帧动画(Sprite Sheet)实战教程
unity·游戏引擎
mxwin9 小时前
Unity URP 多线程渲染:理解 Shader 变体对加载时间的影响
unity·游戏引擎·shader
呆呆敲代码的小Y11 小时前
【Unity工具篇】| 游戏完整资源热更新流程,YooAsset官方示例项目
人工智能·游戏·unity·游戏引擎·热更新·yooasset·免费游戏
nainaire11 小时前
自学虚幻引擎记录1
游戏引擎·虚幻
想你依然心痛14 小时前
HarmonyOS 5.0游戏开发实战:构建高性能2D休闲游戏引擎与 monetization 系统
华为·游戏引擎·harmonyos
黄思搏2 天前
基于标注平台数据的 Unity UI 自动化构建工作流设计与工程实践
ui·unity·蓝湖·vectoui
羊羊20352 天前
开发手札:Unity6000与Android交互
android·unity·android-studio
Zarek枫煜2 天前
C3 编程语言 - 现代 C 的进化之选
c语言·开发语言·青少年编程·rust·游戏引擎
Sator13 天前
Unity AStarPath的踩坑点
unity
榮華3 天前
DOTA全图透视辅助下载DOTA全图科技辅助下载DOTA外挂下载魔兽争霸WAR3全图下载
数据库·科技·游戏·游戏引擎·游戏程序·ai编程·腾讯云ai代码助手