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

脚本解析

相关推荐
在路上看风景12 小时前
4.5 顶点和片元
unity
在路上看风景1 天前
31. Unity 异步加载的底层细节
unity
天人合一peng1 天前
Unity中做表头时像work中整个调整宽窄
unity
小李也疯狂2 天前
Unity 中的立方体贴图(Cubemaps)
unity·游戏引擎·贴图·cubemap
牛掰是怎么形成的2 天前
Unity材质贴图引用陷阱:包体暴涨真相
unity·材质·贴图
呆呆敲代码的小Y2 天前
【Unity工具篇】| 超实用工具LuBan,快速上手使用
游戏·unity·游戏引擎·unity插件·luban·免费游戏·游戏配置表
EQ-雪梨蛋花汤2 天前
【Unity优化】Unity多场景加载优化与资源释放完整指南:解决Additive加载卡顿、预热、卸载与内存释放问题
unity·游戏引擎
我的offer在哪里2 天前
用 Unity 从 0 做一个「可以玩的」游戏,需要哪些步骤和流程
游戏·unity·游戏引擎
泡泡茶壶ᐇ2 天前
Unity游戏开发入门指南:从零开始理解游戏引擎核心概念
unity·游戏引擎
YigAin2 天前
Unity中的Lock,到底在锁什么,什么时候该用?
unity