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. TCP协议是安全的吗?

    2024-02-04 06:44:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-04 06:44:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-04 06:44:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-04 06:44:01       18 阅读

热门阅读

  1. STM32的ADC采集传感器的模拟量数据

    2024-02-04 06:44:01       30 阅读
  2. 理解进位计数制:基数和位权

    2024-02-04 06:44:01       24 阅读
  3. PHP基于文本的简易搜索引擎

    2024-02-04 06:44:01       20 阅读
  4. 大数据领域的数据仓库

    2024-02-04 06:44:01       30 阅读
  5. 软考笔记--数据仓库技术

    2024-02-04 06:44:01       19 阅读
  6. ROS2 CMakeLists.txt 和 package.xml

    2024-02-04 06:44:01       27 阅读
  7. SpringBoot整理-安全(Spring Security)

    2024-02-04 06:44:01       23 阅读