栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Unity3D

Unity Animation获取当前播放动画的名称

Unity3D 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity Animation获取当前播放动画的名称

Unity Animation获取当前播放动画的名称
  • 前言
  • 解决方案

前言

做一个跑酷游戏,用的Animation,至于为什么没用Animator,因为忘了。。。
涉及到动画的暂停和恢复,需要用animation[CurrentPlayingAnimationName(当前动画名称)].speed = 1;和animation[CurrentPlayingAnimationName(当前动画名称)].speed = 0;来控制动画的启动和暂停,所以就需要用到当前播放动画的名称。

解决方案

animation变量为当前的动画组件

    /// 
    /// 动画组件
    /// 
    private Animation animation;
    
    /// 
    /// 获取当前动画名称
    /// 
    private string CurrentPlayingAnimation
    {
        get
        {
            //如果动画正在播放
            if (this.animation.isPlaying)
                //遍历动画列表
                foreach (AnimationState item in this.animation)
                    //如果正在这个动画正在播放,则返回
                    if (this.animation.IsPlaying(item.name))
                        return item.name;
            return null;
        }
    }

使用方法

//暂停当前动画
animation[CurrentPlayingAnimation].speed = 0;
//继续当前动画
animation[CurrentPlayingAnimation].speed = 1;

参考链接: https://answers.unity.com/questions/444500/how-to-get-current-animation-name.html

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/900254.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号