コード例 #1
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Knife")
     {
         asi = ANIM.GetCurrentAnimatorStateInfo(0);
         if (asi.fullPathHash == Animator.StringToHash("Base Layer.Attack"))
         {
             int num = Random.Range(10, 30);
             //执行加分动画
             m_delHitMonster(num);
             UI_BasePlayerInfos.TakeDamage(num);
             Destroy(BC);
             //添加特效
             Instantiate(Resources.Load("IGSoft_Projects/SceneEffects/Common/E_Babble"),
                         new Vector3(transform.position.x, transform.position.y + BC.size.y / 2f, transform.position.z)
                         , Quaternion.identity);
             AudioManager.PlayAudio(gameObject, eAudioType.Audio_Skill, "skill_addbuff");
             m_eState = eMonsterState.Monster_Dead;
             ANIM.SetTrigger("Base Layer.Die");
         }
     }
 }
コード例 #2
0
    void RunAttackRun()
    {
        if (CheckEndOfMove())
        {
            return;
        }

        //计算当前运动的百分比进度
        m_fCurentPercentage = CalculateCurPercentage();
        switch (m_eState)
        {
        case eMonsterState.Monster_RunAway:
        {
            /*
             * 怪兽运动进度, 是否是第一次播放攻击动画 : 只有满足上述两个条件,当前运动进度 > 设定运动进度 && 是第一次进行攻击 -> 执行攻击逻辑
             * */
            if (m_fCurentPercentage > m_fPercentage && m_bIsFirstAttack)
            {
                m_bIsFirstAttack = false;
                //设置转身模式
                m_eState = eMonsterState.Monster_Turn;
                //设置转身朝向
                m_eTurn = eTurnDirection.eTurn_Left;
                //设置当前状态旋转终点
                m_qCurStateQuaternion = m_qTurnQuaternion;
                return;
            }

            //播放前进动画
            ANIM.SetFloat("Speed", 1.0f);
            //修改怪兽位置
            MoveMononster();
            break;
        }

        case eMonsterState.Monster_Dead:
        {
            //判定透明度
            if (m_alpha <= 0)
            {
                Destroy(gameObject);
                return;
            }

            if (null == m_sDeadShader)
            {
                m_sDeadShader             = Shader.Find("Custom/SimpleAlpha");
                m_smr.materials[0].shader = m_sDeadShader;
            }

            m_smr.materials[0].SetFloat("_TransVal", m_alpha);
            m_alpha -= Time.deltaTime * 0.5f;
            transform.Translate(new Vector3(0f, 2 * Time.deltaTime, 0f));

            break;
        }

        case eMonsterState.Monster_Attack:
        {
            //获取当前的动画信息
            asi = ANIM.GetCurrentAnimatorStateInfo(0);
            //判定当前动画是否是idle动画
            if (asi.fullPathHash == Animator.StringToHash("Base Layer.Idle"))
            {
                //代表攻击完毕, 需要转回去
                ANIM.SetFloat("Speed", 1.0f);
                //标识旋转方向
                m_eTurn = eTurnDirection.eTurn_Right;
                //标识旋转状态
                m_eState = eMonsterState.Monster_Turn;
                //标识旋转终点
                m_qCurStateQuaternion = m_qBirthQuaternion;
                return;
            }
            break;
        }

        case eMonsterState.Monster_Turn:
        {
            //旋转怪兽到制定位置 -> Lerp的原理 : Beizier Line.
            transform.rotation = Quaternion.Lerp(transform.rotation, m_qCurStateQuaternion, 10 * Time.deltaTime);
            //判定当前旋转是否到达指定角度
            if (Mathf.Abs(transform.rotation.eulerAngles.y - m_qCurStateQuaternion.eulerAngles.y) < 0.1f)
            {
                //左转
                if (m_eTurn == eTurnDirection.eTurn_Left)
                {
                    //设置当前状态为攻击状态
                    m_eState = eMonsterState.Monster_Attack;
                    //播放攻击动画
                    ANIM.SetTrigger("Base Layer.Attack");
                    //AudioManager.PlayAudio(gameObject, eAudioType.Audio_Skill, "BI_sound");
                    //开启协程等待攻击结束
                    //StartCoroutine(WaitEndOfAttack());
                }
                //右转
                else
                {
                    m_eState = eMonsterState.Monster_RunAway;
                }
            }
            break;
        }
        }
    }