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

相关推荐
习惯就好zz5 分钟前
Godot Player CharacterBody2D 移动和停止配置
游戏引擎·godot·characterbody2d·animationplayer·animationtree
ysn111111 小时前
Unity合批实战
unity·游戏引擎
Howrun7772 小时前
虚幻引擎_玩家控制器APlayerController(进阶)
游戏引擎·虚幻
IMPYLH3 小时前
Lua 的 Package 模块
java·开发语言·笔记·后端·junit·游戏引擎·lua
警醒与鞭策3 小时前
大模型对比
unity·性能优化·c#·游戏引擎·cursor
Howrun7773 小时前
虚幻引擎_玩家控制器APlayerController(初阶)
游戏引擎·虚幻
WarPigs4 小时前
switch和硬编码字典的等效性
unity·c#
没事写写笔记4 小时前
UniTask
unity
秦奈4 小时前
Unity复习学习笔记(八):动画、模型与寻路
笔记·学习·unity
呆呆敲代码的小Y4 小时前
【Unity工具篇】| Unity项目中如何使用LuBan插件,详细集成步骤
游戏·unity·游戏引擎·u3d·luban·免费游戏·unity工具