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

相关推荐
avi91111 小时前
Unity-海水效果+ShaderGraph-非专业不谈虚的效果-分享实用Editor源码
unity·游戏引擎
猫不在5 小时前
MVC和MVVM
unity
老朱佩琪!6 小时前
在Unity中实现状态机设计模式
开发语言·unity·设计模式
憨辰6 小时前
Unity I2多语言拆分方案【内存、包体⬇️】
unity·游戏引擎
jtymyxmz18 小时前
《Unity Shader》12.5 Bloom 效果
unity·游戏引擎
jtymyxmz20 小时前
《Unity Shader》12.6 运动模糊
unity·游戏引擎
jtymyxmz1 天前
《Unity Shader》12.4.2 实现
unity·游戏引擎
sindyra1 天前
Unity UGUI 之 Canvas Scaler
unity·游戏引擎
在路上看风景1 天前
2.Square Grid
unity
程序猿阿伟1 天前
《突破Unity热更新瓶颈:底层函数调用限制与生态适配秘籍》
unity·游戏引擎