Esempio n. 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        ContactPoint2D contactPoint = collision.contacts[0];
        Vector2        normal       = contactPoint.normal;

        switch (contactPoint.collider.tag)
        {
        // 벽돌
        case Common.tagEnvirments:
            if (normal.y < 0 && !isBoxHit)
            {
                isBoxHit = true;
                TileObject tileObject = contactPoint.collider.GetComponent(typeof(TileObject)) as TileObject;
                tileObject?.ActionCall();
            }
            //if (normal.x != 0 && normal.y > 0)
            //{
            //    ignoreMoveForce = true;
            //}
            //else
            //    ignoreMoveForce = false;
            break;

        case Common.tagEnemy:
        {
            if (normal.y > 0)
            {
                Enemy enemy = contactPoint.collider.GetComponent(typeof(Enemy)) as Enemy;
                enemy?.Hit(true, transform.position - contactPoint.collider.transform.position);
                Jump(true);
            }
            else
            {
                // 마리오 죽음
                Hit();
            }
        }
        break;
        }
    }