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

相关推荐
微莱羽墨16 小时前
零、0基础入门Unity 安装详细教程(2026最新版教程,安装Unity看这一篇就够了!)
unity·游戏引擎·unity安装
星辰徐哥16 小时前
Unity C#入门:变量的定义与访问权限(public/private)
unity·c#·lucene
nnsix17 小时前
Unity 刚体的 默认力、瞬时力 区别
unity·游戏引擎
nnsix17 小时前
Unity Sprite的 Generate Physics Shape 参数解释
unity·游戏引擎
魔士于安17 小时前
Unity完整小球迷宫项目
前端·unity·游戏引擎·贴图·模型
め.17 小时前
Unity协程的原理
unity·游戏引擎
天人合一peng1 天前
unity 生成标记根据背景色标记变色
unity·游戏引擎
天人合一peng2 天前
unity 生成标记根据背景色变色为明显的颜色
unity·游戏引擎
魔士于安2 天前
Unity 超市总动员 超市收银台 超市货架 超市购物手推车 超市常见商品
游戏·unity·游戏引擎·贴图·模型
CandyU22 天前
Unity —— 数据持久化
unity·游戏引擎