Sprite color invert

Hi, so I have black sprite and I want it to change color on moving onto other black cube. I tried doing this with depth masks, but I’m new to shaders, so I couldn’t make it work.
Here’s an example of what I’m trying to do:

Does anybody know how to achieve it?

Any help will be apreciated.

if its for a sprite then I don’t have the awnser but if it’s for a mesh then the code would be like this

Shader "Custom/Invert Colors" {
	Properties {
		// defines color property
		_Color("Tint Color", Color) = (1,1,1,1)

		// sets the queue to transparent
		Tags{ "Queue" = "Transparent" }

		Pass { ColorMask 0 } // turns off rendering to all color channels
		Blend OneMinusDstColor OneMinusSrcAlpha //invert blending, so long as FG color is 1,1,1,1
		BlendOp Add // adds source and destination together with specified blend modes

			#pragma vertex vert
			#pragma fragment frag
			uniform float4 _Color;

			struct vertexInput
				float4 vertex: POSITION;
				float4 color : COLOR;

			struct fragmentInput
				float4 pos : SV_POSITION;
				float4 color : COLOR0;

			fragmentInput vert(vertexInput i)
				fragmentInput o;
				o.pos = UnityObjectToClipPos(i.vertex);
				o.color = _Color;
				return o;

			half4 frag(fragmentInput i) : COLOR
				return i.color;


I hope this helps