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

相关推荐
世洋Blog7 小时前
更好的利用ChatGPT进行项目的开发
人工智能·unity·chatgpt
evolution_language16 小时前
Unity场景(Scene)的注意事项和易错点
unity·游戏引擎·scene
EQ-雪梨蛋花汤19 小时前
【AI工具】使用 Doubao-Seed-Code 优化 Unity 编辑器插件:从功能实现到界面美化的完整实践
人工智能·unity·编辑器
g***B73821 小时前
元宇宙游戏引擎
游戏引擎
Dr.勿忘1 天前
开源Unity小框架:高效单例与模块化设计
游戏·unity·开源·c#·游戏引擎·游戏程序·gamejam
jtymyxmz2 天前
《Unity Shader》8.4 透明度混合
unity·游戏引擎
世洋Blog2 天前
利用<<左移运算符优雅的设计游戏能力的任意组合和判断
游戏·unity·c#
毛甘木3 天前
Unity MonoPInvokeCallback 使用教程
c++·unity
心疼你的一切3 天前
Unity开发Rokid应用之离线语音指令交互模型
android·开发语言·unity·游戏引擎·交互·lucene
Sator13 天前
Unity使用OpenXR时,初始化失败的问题
unity·游戏引擎·vr