How can I attach objects like a picture?

I wanna attach an object to another like a picture, when I drag an object near another.
I searched and found some information.

ex)
obj1.transform.parent = obj2.transform;
obj1.transform.localPosition = Vector3.zero;
obj1.transform.localRotation = Quaternion.identity;

But, It makes objects overlapped.
How do I do?.. can anyone help me please?

I’m not entirely sure what you’re trying to do. At the moment it seems like you’re just moving one object to another objects position, the reason they overlap is because you’re telling them to share the same coordinates. There’s a number of ways to make them sit next to each other, but it’ll get more complicated the more complex your objects get. for now just try getting the scale of the object you’re moving to and offset the first objects position by half of that scale.

 obj1.position = obj2.position;
 obj1.position.x/y/z += (obj2.localscale.x/y/z + obj1.localscale.x/y/z)

You can use this shader which offsets the drawn texture so that it is drawn a tiny bit more towards the camera, to solve the overlapping issue. Great for decals.

Shader "Custom/BlendedDecal"
{
	Properties
	{
		_Color ("Tint", Color) = (1,1,1,1)
		_MainTex ("Texture", 2D) = "white" {}
	}
	
	SubShader
	{
		Lighting Off
		ZTest LEqual
		ZWrite Off
		Tags {"Queue" = "Transparent"}
		Pass
		{
			Alphatest Greater 0
			Blend SrcAlpha OneMinusSrcAlpha
			Offset -1, -1
			SetTexture [_MainTex]
			{
				ConstantColor[_Color]
				Combine texture * constant
			}
		}
	}
}