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 动画实现指定时间开始播放

相关推荐
熬夜敲代码的小N2 小时前
Unity WebRequest高级操作:构建高效稳定的网络通信模块
android·数据结构·unity·游戏引擎
萘柰奈3 小时前
Unity【小问题】----URP项目中加载AssetBundle中的预设体即使加载了依赖的材质依然是紫色的问题
unity·游戏引擎·材质
wonder135794 小时前
UGUI合批分析和优化方法整理
unity·ugui
海中有金6 小时前
Unreal Engine 线程模型深度解析[2]
人工智能·游戏引擎·虚幻
海中有金6 小时前
Unreal Engine 内存池浅谈[11]——总结篇
游戏引擎·虚幻
wonder135796 小时前
UGUI鼠标点击到按钮响应流程的源码分析
unity·ugui
熊猫悟道21 小时前
Unity shader 之,Shader内部时间离散处理
unity·游戏引擎·材质·着色器
PA_1 天前
unity Component-Based Architecture游戏框架
游戏·unity·游戏引擎
yi碗汤园1 天前
C#实现对UI元素的拖拽
开发语言·ui·unity·c#
jtymyxmz1 天前
《Unity Shader》11.3.2 广告牌技术
unity·游戏引擎