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中的协程的原理
unity·游戏引擎
垂葛酒肝汤4 小时前
Unity第一个项目
unity·游戏引擎
Sator14 小时前
Unity的InputSystem常见问题和疑惑解答
java·unity·游戏引擎
郝学胜-神的一滴4 小时前
QtOpenGL多线程渲染方案深度解析
c++·qt·unity·游戏引擎·godot·图形渲染·unreal engine
IMPYLH6 小时前
Lua 的 Table 模块
开发语言·笔记·后端·junit·游戏引擎·lua
Howrun7771 天前
虚幻引擎_控制角色移动的三种方法
游戏引擎·虚幻
速冻鱼Kiel1 天前
GASP笔记01
笔记·ue5·游戏引擎·虚幻
孟无岐1 天前
【Laya】Animator2D 使用指南
typescript·游戏引擎·游戏程序·laya
速冻鱼Kiel1 天前
GASP笔记02
笔记·ue5·游戏引擎·虚幻
__water1 天前
RHK《Unity接入PicoSDK入门》
unity·游戏引擎·picosdk