예제 #1
0
    private void MoveMario()
    {
        controller2D.Move(velocity * Time.fixedDeltaTime);

        // After move check to see if we hit a ceiling or the ground.
        // If so we want to reset velocity.y to 0 as it means we're ending
        // a jump potentially.
        if (controller2D.collisions.above || controller2D.collisions.below)
        {
            velocity.y     = 0;
            jumping        = false;
            hitBlockOnJump = false;
        }

        if (controller2D.collisions.left || controller2D.collisions.right)
        {
            velocity.x = 0;
        }

        UpdateAnimations();

        if (!hitBlockOnJump)
        {
            GameObject ceilingObject = controller2D.HitCeilingObject();
            GameObject groundObject  = controller2D.HitGroundObject();

            if (ceilingObject)
            {
                if (ceilingObject.tag == "BrickBlock")
                {
                    BrickBlock brickBlock = ceilingObject.GetComponent <BrickBlock>();
                    brickBlock.HitBlock();
                    hitBlockOnJump = true;
                }

                if (ceilingObject.tag == "QuestionBlock")
                {
                    QuestionBlock questionBlock = ceilingObject.GetComponent <QuestionBlock>();
                    questionBlock.HitBlock();
                    hitBlockOnJump = true;
                }
            }

            if (groundObject)
            {
                if (groundObject.tag == "Enemy")
                {
                    Enemy enemy = groundObject.GetComponent <Enemy>();
                    enemy.Damage();
                    hitBlockOnJump = true;
                    velocity.y     = enemyJumpVelocity;
                    jumping        = true;
                }
            }
        }

        GameObject itemObject = controller2D.HitItem();

        if (itemObject)
        {
            if (itemObject.tag == "Mushroom")
            {
                MakeMarioBig();
                Destroy(itemObject);
            }
        }
    }