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

相关推荐
Artistation Game10 小时前
九、怪物行为逻辑
游戏·unity·游戏引擎
百里香酚兰11 小时前
【AI学习笔记】基于Unity+DeepSeek开发的一些BUG记录&解决方案
人工智能·学习·unity·大模型·deepseek
妙为11 小时前
unreal engine5制作动作类游戏时,我们使用刀剑等武器攻击怪物或敌方单位时,发现攻击特效、伤害等没有触发
游戏·游戏引擎·虚幻·碰撞预设
dangoxiba13 小时前
[Unity Demo]从零开始制作空洞骑士Hollow Knight第十三集:制作小骑士的接触地刺复活机制以及完善地图的可交互对象
游戏·unity·visualstudio·c#·游戏引擎
先生沉默先1 天前
使用Materialize制作unity的贴图,Materialize的简单教程,Materialize学习日志
学习·unity·贴图
十画_8242 天前
Visual Studio 小技巧记录
unity·visual studio
red_redemption2 天前
cpp,git,unity学习
git·unity·游戏引擎
tealcwu2 天前
【Unity踩坑】Unity更新Google Play结算库
unity·游戏引擎
先生沉默先2 天前
unity 默认渲染管线材质球的材质通道,材质球的材质通道
unity·游戏引擎·材质
白鹭float.2 天前
【Unity AI】基于 WebSocket 和 讯飞星火大模型
人工智能·websocket·unity