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

相关推荐
Solange__3 小时前
AI世界模型、3D场景生成和游戏引擎怎么选?按5类任务比较交互、物理与导出
开发语言·人工智能·游戏·平面·3d·自然语言处理·游戏引擎
LF男男4 小时前
Flower Defense—UIFacade
unity
呆呆敲代码的小Y4 小时前
【实战精选面试题】Unity精选面试题详细解答,按模块整理汇总
人工智能·游戏·unity·游戏引擎
小贺儿开发14 小时前
《流光绘忆》Unity 沉浸式光影互动
科技·unity·ai·程序员·工具·互动·光影
Aman198418 小时前
Claude Code做Unity项目移植(一):从零散工具到团队式
unity·游戏开发·vibe coding·claude code·项目迁移
地狱为王20 小时前
Unity使用VoxLock实现语音隔离
unity·游戏引擎·音频处理·voxlock
Jmyd01231 天前
博物馆数字展厅系统架构设计:实景采集到云渲染全链路
unity·系统架构·博物馆·数字展厅·博物馆数字化
解决小子1 天前
【虚幻引擎】【GAS】模块详解
游戏引擎·虚幻·gas
一只大鸽子1 天前
游戏开发笔记0-Godot启动
笔记·游戏引擎·godot
weixin_424294671 天前
对于未加入 Script Execution Order 的脚本
unity