RaycastHit2D problem

Help me figure out what’s wrong.

I do a Raycast detection:

    private void Check()
        float high = 1.1f, step = 0.35f;
        for (float i = -0.1f; i < high; i += step)
            RaySidePointStart = transform.up * i + transform.position;

            RaycastHit2D RaySide = Physics2D.Raycast(RaySidePointStart, vectorSideRay,rayDistanceSide, LayerWall);
            Debug.DrawRay(RaySidePointStart, vectorSideRay * rayDistanceSide, Color.blue);

            if (RaySide.collider != null)
                TouchedWall = true;
                Debug.Log("This is WALL!!!");
            else //if (RaySide.collider == null)
                TouchedWall = false;

and this is what happens:


Why the flag “TouchedWall” does not work when the top ray does not touch the collider?

Did you add collider to the bottom box or wall.