Block camera raycast by UI

I make a painting game and have two cameras: one for UI and one for picture. Camera, that draws picture has a script that reduces it orthographic size, so it works like zoom. Also, then I touch some part of the picture, it should change color, so I throw ray from the game camera and look for image part to change it color. When zoom is high, parts of my picture can be positioned under UI elements, and that’s fine, UI elements should block raycasts, so when you press button, the picture part under it should not be colored. The problem is, as I understand it, that game camera draws only game elements layer, not UI, and when I throw ray, it just doesn’t see any UI elements, caus it just don’t draw them. So as a result picture as colored and button is clicked at the same time. Still I need some solution for this problem, appreciate any help and ideas.

Solved this problem using first method from