Unity animator 动画实现指定时间开始播放

在我们使用Unity帧动画时,如用到同一个帧动画的部分动画,那么我们可以考虑用指定播放时间的方法实现。

如我在场景中创建一个2D帧动画,并创建一个2D对象使用该帧动画。

然后复制该2D对象,并创建一个控制脚本GameController1.cs:

复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameController1 : MonoBehaviour
{
    public Animator animator;
    public bool simple;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void BeginPlay()
    {
        if(simple)
        {
            animator.PlayInFixedTime(0, -1, 1);
        }
        
    }
}

这里animator.PlayInFixedTime(0, -1, 1);就是用于指定动画开始播放时间的方法。

把脚本放到复制对象中。

然后在帧动画播放结束后调用BeginPlay()方法,这样就可以实现帧动画播放完毕后,再从指定时间开始播放。

效果如下:

Unity animator 动画实现指定时间开始播放

相关推荐
天人合一peng15 小时前
Hololens2 发布debug调试安装至hololens2
unity·xr
Yuk丶15 小时前
UE4 与 UE5:技术差异深度解析
c++·ue5·游戏引擎·ue4·游戏程序·虚幻
l1t17 小时前
DeepSeek总结的Delta 成长记:写入、Unity Catalog 和时间旅行
数据库·人工智能·unity
年少无知且疯狂17 小时前
【Unity】Mirror网络框架
unity
顾温17 小时前
协程结束——实测
开发语言·unity·c#
小白学鸿蒙1 天前
Unity 3D 2023解压安装,配置安卓运行环境后打包安卓应用(踩坑无数之差点放弃)
android·unity·游戏引擎
__water2 天前
【关于unity打包Android失败问题】
android·unity
mascon2 天前
Unity 编辑器扩展
unity·编辑器·游戏引擎
程序员正茂2 天前
Unity3d使用MQTT异步连接服务端
mqtt·unity·异步
mxwin2 天前
在unity shader中,通过pass产生阴影,通过主pass的光照 接收阴影!那么问题来了,是先产生阴影吗?还是先接收阴影,执行顺序是啥呢
数码相机·unity·游戏引擎·shader