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

相关推荐
mxwin5 小时前
Unity Shader URP:法线如何进行光照计算
unity·游戏引擎·shader
郝学胜-神的一滴6 小时前
中级OpenGL教程 009:用环境光告别模型死黑
前端·c++·unity·godot·图形渲染·opengl·unreal
一锅炖出任易仙8 小时前
创梦汤锅学习日记day30
学习·ai·ue5·游戏引擎
mxwin17 小时前
Unity URP 中的法线生成完全指南
unity·游戏引擎
游乐码17 小时前
Unity基础(十五)LineRender画线功能
unity·游戏引擎
玖玥拾18 小时前
Cocos学习笔记:瓦片地图与坐标转换
游戏引擎·cocos2d
小贺儿开发19 小时前
Unity3D 图片循环查看器
unity·工具·图片·列表·循环·ugui·互动
晓13131 天前
【Cocos Creator 3.x】篇——第二章 入门
前端·javascript·游戏引擎
玖玥拾1 天前
Cocos学习笔记:粒子系统与对象层批量处理
游戏引擎·cocos2d
是果果呀儿1 天前
Vuforia实现物体旋转、移动、缩放
unity·增强现实