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

相关推荐
游乐码14 小时前
UnityGUI(五)GUI控件综合使用
开发语言·unity·c#
LF男男14 小时前
TshitBullect.cs
unity
游乐码1 天前
Unity(十六)切换场景及鼠标相关
unity·游戏引擎
FakeEnd1 天前
Unity开发笔记6
笔记·unity·游戏引擎
游乐码1 天前
Unity(十七)Unity随机数及Unity委托
unity·游戏引擎
ellis19701 天前
Unity性能优化之检测工具Profiler
unity·性能优化
RPGMZ1 天前
RPGMZ游戏引擎 一个窗口 文本居中显示
开发语言·javascript·游戏引擎·rpgmz
tohand1 天前
Unity 完美假阴影实现文档
unity·游戏引擎
@蓝莓果粒茶1 天前
【Unity笔记】保姆级AssetBundle详解(含代码+避坑指南)
笔记·游戏·unity
Zephyr_01 天前
Unity2D游戏制作
游戏·unity