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

脚本解析

相关推荐
技术小甜甜16 小时前
[Godot] 解决导出APK安装失败的常见问题:深入分析与调试方法
游戏引擎·godot·游戏开发
老朱佩琪!21 小时前
Unity桥接模式
unity·设计模式·c#·桥接模式
技术小甜甜21 小时前
[Godot][入门] 安装与版本选择:3.x 还是 4.x?(按项目类型一键决策)
游戏引擎·godot·游戏开发·2d
陈言必行21 小时前
Unity 之 物理引擎中三种刚体力施加方式详解
unity·游戏引擎
foreveryao12321 小时前
Unity渲染流程(底层逻辑)
unity·游戏引擎·图形渲染
small-pudding1 天前
Unity中的PBR(基于物理的渲染)
unity·游戏引擎
CreasyChan1 天前
3D游戏数学基础指南
游戏·3d·unity·数学基础
平行云2 天前
Enscape × Paraverse | 从设计到一键发布、网页分享、实时交互的全新体验
unity·ue5·xr·3dsmax·webgl·实时云渲染·云桌面
老朱佩琪!2 天前
Unity迭代器模式
unity·设计模式·迭代器模式
程序猿多布2 天前
Unity 多语言系统实现
unity·多语言