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

相关推荐
在路上看风景37 分钟前
32. 代码优化
unity
在路上看风景1 小时前
01. 编辑器外观
unity
CreasyChan2 小时前
unity C# 实现屏蔽敏感词
unity·c#·游戏引擎
玉梅小洋3 小时前
Unity 2D游戏开发 Ruby‘s Adventure 2:主角和第一脚本
游戏·unity·游戏引擎·游戏程序·ruby·游戏开发
CG_MAGIC3 小时前
3D 烘焙资产导出:多引擎(Unity/Unreal)适配技巧
3d·unity·游戏引擎·效果图·建模教程·渲云
云上空20 小时前
腾讯云使用对象存储托管并分享WebGL小游戏(unity3d)(需要域名)
unity·腾讯云·webgl·游戏开发·对象存储·网页托管
小贺儿开发1 天前
Unity3D VR党史主题展馆
unity·人机交互·vr·urp·展馆·党史
TopGames1 天前
Unity实现10万人同屏动态避障和导航寻路系统 支持3D地形
unity·性能优化·游戏引擎
在路上看风景1 天前
01. GUIContent
unity
托洛夫斯基扎沙耶1 天前
Unity中状态机与行为树的简单实现
unity·游戏引擎