Snap object to object

Hi guys.
I’m making a snapping games. In the picture below, there are 2 objects -the black and silver,they have the same size. I had a script for drag-and-drop object, so now I’m trying to create a script that when I move an object to another one and then release , it will fit exactly into that object. Can anyone help me? thanks in advance :smiley:

alt text

//Drag-and-Drop script
 
using UnityEngine;
 
using System.Collections;
 
public class MovePoint2 : MonoBehaviour
{
    private Vector3 screenPoint;
    private Vector3 offset;
 
    void OnMouseDown() 
    { 
       screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
 
       offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
 
       Screen.showCursor = false;
 
 
    }
 
    void OnMouseDrag() 
    { 
       Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
 
       Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
 
       transform.position = curPosition;
 
    }
 
    void OnMouseUp()
    {
       Screen.showCursor = true;
    }
}

You need to define what is the target position and then apply that position when you release the button:

void OnMouseUp()
{
   Screen.showCursor = true;
   movingObject.position = target.position;
}