示例#1
0
        private IEnumerator Dash()
        {
            m_isDashing     = true;
            m_dashTimer     = m_dashDuration;
            m_jumpInterrupt = true;
            m_superArmored  = true;

            m_dashTrigger.Enable(m_dashAttack.attackDatas[0]);

            float dir;

            if (m_dashDir == 0f) // No input -> player Direction
            {
                dir = (transform.rotation.eulerAngles.y == 0f) ? 1f : -1f;
            }
            else                   // input Direction
            {
                dir = (m_dashDir > 0f) ? 1f : -1f;
            }

            m_beforeDashXpos = transform.position.x;

            LayerMask dashLayers = (1 << LayerMask.NameToLayer("Solid")) | (1 << LayerMask.NameToLayer("PlayerRestricted"));

            RaycastHit hit;
            bool       hasHit = m_positionDetector.BoxCast(dir * Vector3.right, m_dashLength, out hit, dashLayers);

            float afterDashXpos = hasHit ? hit.point.x : m_beforeDashXpos + (m_dashLength * dir);


            float t = 0f;

            while (t <= 1.0)
            {
                //Interrupt if touching any solid object/border screen
                if (m_dashInterrupt)
                {
                    m_dashInterrupt = false;
                    break;
                }

                //momentum
                m_rigidbody.velocity = Vector3.zero;

                float nextXpos = Mathf.Lerp(m_beforeDashXpos, afterDashXpos, t);

                transform.position = new Vector3(nextXpos,
                                                 transform.position.y,
                                                 transform.position.z);

                t += Time.deltaTime / m_dashDuration;
                yield return(null);
            }

            m_dashTrigger.Disable();

            m_superArmored  = false;
            m_dashTimer     = m_dashCooldown;
            m_isDashing     = false;
            m_dashInterrupt = false;
            m_jumpInterrupt = false;

            m_animator.SetBool("Dash", false);

            yield return(new WaitForEndOfFrame());
        }