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

相关推荐
董董女友2 小时前
unity mcp 配置指南
unity·游戏引擎
垂葛酒肝汤7 小时前
Unity的可视化网格和文字标签
unity·游戏引擎
魔士于安8 小时前
Unity UI图片 复活节UI,卡通风格
游戏·ui·unity·游戏引擎·材质·贴图
weixin_423995008 小时前
unity 团结开发小游戏,加载AssetBundles(第二种方法)
unity·游戏引擎
魔士于安9 小时前
unity 卡通风整套资源 小鸟N套带动作+一套卡通风村落 和 相关道具+落叶粒子效果 buildin
游戏·unity·游戏引擎·贴图·模型
伽蓝_游戏10 小时前
第一章:解构游戏资源
游戏·unity·性能优化·c#·游戏引擎·游戏程序·assetbundle
星辰徐哥11 小时前
Unity C#入门:Visual Studio与Unity的关联配置
unity·c#·visual studio
Sparkle Star11 小时前
Unity VRTK4包导入和依赖关系
unity·游戏引擎
WiChP13 小时前
【V0.1B7】从零开始的2D游戏引擎开发之路
游戏引擎
Sparkle Star15 小时前
Unity VRTK4+SteamVR传送组件使用和层级关系
unity·游戏引擎