コード例 #1
0
    // TODO: Merge with BunnyCrownState
    public override void HandleCollision(GameObject player, Collider2D collision, ref Vector3 velocity)
    {
        Bunny  bunny = collision.GetComponent <Bunny>();
        Player enemy = collision.GetComponent <Player>();

        Vector3 knockbackForce = velocity;

        if (bunny)
        {
            HitRecord hitRecord = new HitRecord();
            bunny.Hit(player, ref hitRecord, knockbackForce);
        }
        else if (enemy)
        {
            // Trying to hit the enemy player
            HitRecord hitRecord = new HitRecord();
            enemy.Hit(player, ref hitRecord, knockbackForce);

            // If an enemy is hit, the dash stops
            Player self = player.GetComponent <Player>();
            if (self.collisionInfo.below)
            {
                self.controller.SwitchState(PlayerController.States.IDLE);
            }
            else
            {
                self.controller.SwitchState(PlayerController.States.AIRBORNE);
            }

            // If the dash was reflected because of a collision with a dashing player, both players are repelled in the opposite facing direction
            if (hitRecord.reflected)
            {
                Player  hitPlayer        = hitRecord.hitObject as Player;
                Vector2 reflectDirection = hitPlayer.transform.position - player.transform.position;
                reflectDirection.Normalize();

                velocity = reflectDirection * 10.0f;

                Debug.Log("Reflected!");
            }
        }
    }