Пример #1
0
    private void Jump()
    {
        float jumpVal = Input.GetKeyDown(KeyCode.Space) ? jumpForce : 0.0f;

        switch (_jumpState)
        {
        case JumpState.Grounded:
            if (jumpVal > 0.0f)
            {
                _jumpState = JumpState.Jumping;
                Debug.Log("JumpState: " + _jumpState.ToString());
            }
            break;

        case JumpState.Jumping:
            if (jumpVal > 0.0f)
            {
                _jumpState = JumpState.DoubleJumping;
                Debug.Log("JumpState: " + _jumpState.ToString());
            }
            break;

        case JumpState.DoubleJumping:
            jumpVal = 0.0f;
            break;
        }

        Vector3 jumping = new Vector3(0.0f, jumpVal, 0.0f);

        rb.AddForce(jumping);
    }
Пример #2
0
    private void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Collider")
        {
            Vector2 normal = col.contacts[0].normal;
            if (!onGoingCollisions.ContainsKey(col.gameObject))
            {
                onGoingCollisions.Add(col.gameObject, normal);
            }
            if (IsGround(normal))
            {
                jumpState = JumpState.Grounded;
                Debug.Log(jumpState.ToString());
                ySpeed = 0;
            }
        }

        Debug.Log("Enter " + col.gameObject.name + " " + onGoingCollisions.Count);
    }