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

相关推荐
_Cherry|5 小时前
Unity按钮动态效果
unity·游戏引擎
_Cherry|6 小时前
Unity读取文件夹内容
unity·c#
lrh30257 小时前
Custom SRP - 15 Particles
unity·渲染管线·粒子·srp·扰动效果
璞瑜无文8 小时前
Unity 游戏开发之布局(二)
unity·c#·游戏引擎
高远-临客11 小时前
unity IL2CPP模式下中使用UMP插件打包后无法播放视频监控报错问题解决方案
android·unity·音视频
_Cherry|11 小时前
Unity中窗口调整
unity·c#·游戏引擎
qq_4286396113 小时前
虚幻基础:特效
游戏引擎·虚幻
qq_4286396115 小时前
虚幻基础:将角色的模型替换为自己的模型
游戏引擎·虚幻
_Cherry|16 小时前
Unity在屏幕上滑动
unity·游戏引擎
_Cherry|16 小时前
Unity中使用AVPRO播放视频
unity·c#·音视频