Alpha Shader not working with obj collision

I’ve been trying to learn shader code, and am having trouble getting the alpha transparency to work correctly when the mesh is inside another one. In the picture below, the ball is completely inside the box and is being rendered like it is in front of the box when the alpha is off. When the alpha is on both are visible but it still looks like the ball is in front of the square. At some angles when the alpha is off the ball is not visible.

How can I stop this from happening?

32289-shaderproblems.jpg

Properties {
		_MainColor ("Main Color", Color) = (1, 1, 1, 1)
		_RimColor ("Rim Color", Color) = (0, 0, 0, 1)
		_RimPower ("Rim Power", Range (-1, 10)) = 3.0
		_AlphaRange ("Alpha Range", Range (0, 1)) = 1
		_RimRange ("Rim Range", Range (.1, 2.5)) = 0
		
		
	}
	SubShader {
		Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }  
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert alpha

		struct Input {
			float4 color : Color;
			float3 viewDir;
		};

		float4 _MainColor;
		float4 _RimColor;
		float _RimPower;
		float _AlphaRange;
		float _RimRange;
		
		void surf (Input IN, inout SurfaceOutput o) { 
													
			
			IN.color = _MainColor;
			half rim = _RimRange - saturate(dot(normalize(IN.viewDir), o.Normal)); 		
			o.Emission = _RimColor.rgb * pow(rim, _RimPower);					
			o.Alpha = _AlphaRange; 
			o.Albedo =  _MainColor;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

Have you tried playing with setting various blending types? I don’t know what result exactly you want, but it seems like this is what you should look into.

Here are some examples:

Transparency

Order-Independent Transparency