Render part of object with alpha of other object

Hi,
I am trying to render part of an object based on the alpha of another object.

Object A = black

Object B = red

The top left represents just two planes with textures and transparency maps. What I want is what’s on the bottom right, i.e. I want object B to only render based off of its own alpha and object A’s alpha. Both objects are different sizes, and object B will be moving. What would be the best way to go about doing this?
Thanks in advance : )

Your best bet is probably to use stencil.

Render object A with stencil writes on (see Unity - Manual: ShaderLab command: Stencil)
writing your specified stencil to the stencil buffer. You probably want to use cutout or manually clip in the shader to make sure stencil is not written in the transparent areas.

Then render object B with stencil test on, and compare against the written value from object A. This should give you your desired effect.