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

相关推荐
归真仙人1 天前
【UE】UMG安卓相关问题
android·ue5·游戏引擎·ue4·虚幻·unreal engine
BuHuaX1 天前
Unity项目怎么接入抖音小游戏?
unity·c#·游戏引擎·wasm·游戏策划
Sator11 天前
unity Rayfire破碎插件的踩坑点
unity·游戏引擎
鱼蛋-Felix1 天前
C#浮点数在部分国家解析失效问题
开发语言·unity·c#
_风华ts1 天前
虚幻引擎碰撞相关的属性
游戏引擎·虚幻·collision
龚子亦1 天前
【Jenkins】实现Unity远程自动化打包
unity·自动化·jenkins
_风华ts2 天前
虚幻引擎RPC
rpc·游戏引擎·虚幻
垂葛酒肝汤2 天前
放置挂机游戏的离线和在线收益unity实现
游戏·unity·c#
孟无岐2 天前
【Laya】Base64Tool 编码工具类使用说明
typescript·游戏引擎·游戏程序·laya
康de哥2 天前
在OpenCode中配置unity3d-mcp
unity·glm-4.7·minimax m2.1·opencode·unity3d-mcp