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

相关推荐
Octopus20772 小时前
【Godot】@export_multiline
游戏引擎·godot
HELLOMILI5 小时前
[Unity3D] 动态立方体贴图系统
游戏·unity·游戏引擎·图形渲染·着色器
虾球xz14 小时前
游戏引擎学习第151天
学习·游戏引擎
SendSi21 小时前
Unity辅助工具_头部与svn
unity·svn·游戏引擎
虾球xz1 天前
游戏引擎学习第149天
人工智能·学习·游戏引擎
程序员正茂1 天前
Unity安卓Android从StreamingAssets加载AssetBundle
android·unity·assetbundle·streamingassets
free-elcmacom1 天前
<3D建模>.max文件转换为.fbx文件
unity·3dmax·建模·文件转换
PassionY2 天前
Unity DOTS从入门到精通之 C# Job System
unity·ecs·dots·jobsystem·burst·baker·entities
red_redemption2 天前
Unity--Cubism Live2D模型使用
unity·live2d·cubism sdk
咩咩觉主2 天前
C# &Unity 唐老狮 No.6 模拟面试题
开发语言·unity·面试·c#·游戏引擎·唐老师