Beispiel #1
0
    private void dash()
    {
        switch (m_dashState)
        {
        case DashState.Ready:
            //Dash can be only used in movement
            if (System.Math.Round(rigidbody.velocity.x, 2) == 0)
            {
                return;
            }

            if (InputSystem.Dash(playerIndex))
            {
                //Hide the body
                //bodyRenderer.SetActive(false);
                //Set the sprite to right side
                dashRenderer.flipX = rigidbody.velocity.x < 0;
                dashRenderer.gameObject.SetActive(true);

                m_dashSign = Mathf.Sign(rigidbody.velocity.x);

                m_dashTime = 0;

                m_dashState = DashState.Dashing;
            }
            break;

        case DashState.Dashing:
            m_dashTime += Time.deltaTime;

            //Do the dash!
            //rigidbody.AddForce(new Vector2(Mathf.Sign(rigidbody.velocity.x) * m_dashSpeed * Time.deltaTime, 0), ForceMode2D.Force);

            rigidbody.velocity = new Vector2(m_dashSign * m_dashSpeed, rigidbody.velocity.y);

            if (m_dashTime >= m_dashDuration)
            {
                m_dashTime = 0;
                //bodyRenderer.SetActive(true);
                dashRenderer.gameObject.SetActive(false);
                m_dashState = DashState.DashingCooldown;
            }

            break;

        case DashState.DashingCooldown:
            m_dashTime += Time.deltaTime;

            //Small delay;
            if (m_dashTime >= m_dashDuration)
            {
                m_dashTime  = 0;
                m_dashState = DashState.Ready;
            }
            break;
        }
    }