• 【转】unity Animator 怎么判断一个动画播放结束


    关于unity Animator 怎么判断一个动画播放结束这里有几种方法。希望对大家有帮助。还有其他办法的可以分享一下


         第一种方法:在动画结束帧后面加个动画事件,调用下含这个变量的函数接口不是可以了?

    如图,找到动画的inspector面板,在里面有个Events下拉条,下拉后在想要的帧的位置添加事件函数,函数名字记得在使用这个动画的物体的脚本里面写好,否则会报错

         第二种方法:试试animator上面那个 exit time

         第三种方法:

                               //获取动画层 0 指Base Layer.
                               AnimatorStateInfo stateinfo = animator.GetCurrentAnimatorStateInfo(0);
                               //如果正在播放walk动画.
                               if(stateinfo.IsName("Base Layer.walk"))
                             {
                             }

       问:请问一下动画状态机怎么判断动画是否播完了?

         答:   

      1. 脚本参考

      AnimatorStateInfo.normalizedTime

      float normalizedTime;
      Description:
      Normalized time of the State.
      The integer part is the number of time a state has been looped. The fractional part is the % (0-1) of progress in the current loop.

      2. 代码如下:

      

    复制代码
     1 private Animator animator;
     2     void Start()
     3     {
     4         animator = this.GetComponent<Animator>();
     5     }
     6 
     7     void Update()
     8     {
     9         AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
    10         // 判断动画是否播放完成
    11         if (info.normalizedTime >= 1.0f)
    12         {
    13             DoSomething();
    14         }
    15     }

    unity3d animation判断动画播放结束

      
    1. if (anim.IsPlaying("roar") && anim["roar"].normalizedTime >= 1)  
    bool IsAnimationPlaying(GameObject objWithAnimation,string animationName)
    
    
        {       
    
     return  objWithAnimation.animation.IsPlaying(animationName)&&objWithAnimation.animation[animationName].normalizedTime<<span>1.0f;
        }    }

    判断某个动画是否播放完毕。

    IEnumerator WaitForAnimationPlayOver(GameObject objWithAnimation,string animationName)
    
    
        {  
    
          yield return new WaitForSeconds(objWithAnimation.animation[animationName].length);
        }    }

    等待某个动画播放完成。

    normalizedTime: 范围0 -- 1,  0是动作开始,1是动作结束

  • 相关阅读:
    【原】cookie和session的区别
    【总结】资源汇总(二)
    【总结】资源汇总(一)
    【原】linux设置网络延迟/丢包操作
    【原】Web Polygraph 安装
    【原】openresty学习
    【原】nginx配置文件
    【原】postman常用设置全局变量的js片段
    application.yml配置文件没有出现小绿叶子
    The project com.myself.springcloud:cloud2021:1.0-SNAPSHOT (D:ideaOldProjectcloud2021pom.xml) has 1 error;idea Module '****' already exist in project. Please, specify another name.
  • 原文地址:https://www.cnblogs.com/mimime/p/6599798.html
Copyright © 2020-2023  润新知