예제 #1
0
    // Checks if the player is grounded or if they are constantly touching an enemy
    private void OnCollisionStay2D(Collision2D collision)
    {
        if (CheckGrounded() == true && isInAir == true)
        {
            if (isHighFall == true)
            {
                // If the player lands on the ground while in a high fall, they will do a short hop
                ResetHighFall();
                isJumping       = true;
                isMovingUpwards = true;
                Invoke("StopVerticalIncrease", highFallBounceTimer);
            }
            else
            {
                isJumping = false;
                isInAir   = false;

                // If the player is flying, they automatically do an airpuff
                if (isFlying == true && isExhaling == false)
                {
                    GameObject spawned = Instantiate(airPuffPrefab, inhaleHitboxChild.transform.position, Quaternion.identity, gameObject.transform);
                    playerGraphics.ChangeSprite("isAirPuffing");
                    isExhaling = true;
                    if (isFacingRight == false)
                    {
                        spawned.GetComponent <SpriteRenderer>().flipX = true;
                    }
                    Invoke("StopFlying", exhaleResetTimer);
                }
                else if (isInhaling == false)
                {
                    // Unless the player is inhaling, they will do a quick landing animation
                    isLanding = true;
                    if (IsInvoking("StopLandingAnimation") == false)
                    {
                        Invoke("StopLandingAnimation", 0.1f);
                    }
                }
            }
        }
        else if (CheckGrounded() == true)
        {
            // If the player is grounded and is ducking on a PassBothGround platform, they will go through it
            if (collision.gameObject.tag == "PassBothGround" && isDucking == true)
            {
                StartCoroutine("ResetPassBothPlatform", collision.gameObject.GetComponent <PlatformEffector2D>());
            }
        }

        if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "MiniBoss")
        {
            // The player takes damage accordingly
            PlayerHurt(collision.gameObject.GetComponent <BaseEnemy>().attackPower);
        }
    }