• Unity3D 动画状态机简单控制核心代码


    状态机是这样的

    包含静止、跑、攻击、死亡四个动画

    下面是核心代码(PS:代码高亮插件出问题了,将就看一下吧。。)

    AnimatorStateInfo stateInfo = m_ani.GetCurrentAnimatorStateInfo(0);
    
            if (stateInfo.fullPathHash == Animator.StringToHash("Base Layer.idle") && !m_ani.IsInTransition(0))
            {
                m_ani.SetBool("idle", false);
    
                m_timer -= Time.deltaTime;
                if (m_timer > 0)
                    return;
    
                if (Vector3.Distance(m_transform.position, m_player.m_transform.position) < 1.5f)
                {
                    m_ani.SetBool("attack", true);
                }
                else
                {
                    m_timer = 1;
                    m_agent.SetDestination(m_player.m_transform.position);
                    m_ani.SetBool("run", true);
                }
            }
    
            if (stateInfo.fullPathHash == Animator.StringToHash("Base Layer.run") && !m_ani.IsInTransition(0))
            {
                m_ani.SetBool("run", false);
    
                m_timer -= Time.deltaTime;
                if (m_timer < 0)
                {
                    m_agent.SetDestination(m_player.m_transform.position);
    
                    m_timer = 1;
                }
    
                if (Vector3.Distance(m_transform.position, m_player.m_transform.position) <= 1.5f)
                {
                    m_agent.Stop();
                    m_ani.SetBool("attack", true);
                }
            }
    
            if (stateInfo.fullPathHash == Animator.StringToHash("Base Layer.attack") && !m_ani.IsInTransition(0))
            {
                RotateTo();
                m_ani.SetBool("attack", false);
    
                if (stateInfo.normalizedTime >= 1.0f)
                {
                    m_ani.SetBool("idle", true);
    
                    m_timer = 2;
                }
            }
  • 相关阅读:
    bbs树形打印(一)
    ORM
    kafka的分区
    Content-type"是"application/json的作用
    idea增强for循环
    rabbitmq的发布订阅
    搭建mqtt服务器apollo
    kafka生产者集群和分区,消费者轮询接收
    http实时推送技术
    Kafka:Configured broker.id 2 doesn't match stored broker.id 0 in meta.properties.
  • 原文地址:https://www.cnblogs.com/fws94/p/6591275.html
Copyright © 2020-2023  润新知