示例#1
0
    public override IEnumerator DoLogic()
    {
        while (!isExitState)
        {
            if (stateCtrl.GetNextState() != null && stateCtrl.GetNextState() != fsm.CurrentState)
            {
                fsm.PerformState(stateCtrl.GetNextState()); Debug.Log("NEXTSTATE");
                stateCtrl.SetNextState(this.ID);
                break;
            }
            if (Mathf.Abs(attr.myJoystick.axisX.axisValue) > 0.1f || Mathf.Abs(attr.myJoystick.axisY.axisValue) > 0.1f)
            {
                //SetIdle();
                fsm.PerformTransition(Transition.IsMove);
                break;
            }
            if (shoot)
            {
                //AttackTarget(attr.m_PlayerInfo.M_AttackDistance);
                //AttackForword();

                //if (!m_animator.GetCurrentAnimatorStateInfo(0).IsName("Attack1"))
                //{
                //    //只适用于当前职业 还需扩展
                //    //播放射击动画
                //    m_animator.speed = 1.5f;
                //    m_animator.SetInteger("AttackNum", 1);
                //    m_animator.SetBool("Attack", true);
                //    //yield return new WaitForSeconds(0.5f);

                //    //加载子弹
                //    yield return new WaitForSeconds(0.4f);

                //    GameObject go = bp.GetArrow();
                //    go.SetActive(true);
                //    go.transform.position = attr.transform.position + new Vector3(0, 1f, 0);
                //    go.transform.forward = attr.transform.forward;
                //    go.transform.rotation = attr.transform.rotation;
                //    shoot = false;
                //    yield return new WaitForSeconds(0.2f);
                //    //Debug.Log(attr.m_PlayerInfo.M_AttackDistance);
                //    m_animator.SetInteger("AttackNum", 0);
                //    m_animator.speed = 1f;

                //}


                if (!m_animator.GetCurrentAnimatorStateInfo(0).IsName("Attack1"))
                {
                    Collider[] cols = Physics.OverlapSphere(attr.transform.position, 5);
                    if (cols.Length > 0)
                    {
                        foreach (Collider c in cols)
                        {
                            if (c.tag == "Enemy")
                            {
                                Debug.Log("Enemy: " + c.name);
                                targetEnemy = c.transform;
                            }
                        }
                    }
                    Quaternion newRotation = new Quaternion(0, 0, 0, 0);
                    if (targetEnemy == null)
                    {
                        newRotation = attr.transform.rotation;
                    }
                    else
                    {
                        newRotation = Quaternion.LookRotation(targetEnemy.position - attr.transform.position);
                        attr.TargetRotation(newRotation);//修改朝向
                    }
                    //attr.transform.rotation = Quaternion.Lerp(attr.transform.rotation, newRotation, Time.deltaTime * 5);


                    m_animator.speed = 1.5f;
                    m_animator.SetInteger("AttackNum", 1);
                    m_animator.SetBool("Attack", true);
                    yield return(new WaitForSeconds(0.4f));

                    GameObject go = bp.GetArrow();//加载子弹
                    go.SetActive(true);
                    go.transform.position = attr.transform.position + new Vector3(0, 1f, 0);
                    go.transform.forward  = attr.transform.forward;
                    go.transform.rotation = attr.transform.rotation;
                    shoot = false;
                    yield return(new WaitForSeconds(0.2f));

                    //Debug.Log(attr.m_PlayerInfo.M_AttackDistance);
                    m_animator.SetInteger("AttackNum", 0);
                    m_animator.speed = 1f;
                    attr.StopRotation();
                }
            }

            yield return(null);
        }
    }