center a cube on the cursor when it is clicked

Hi everyone,

I think I finally found the formula I was looking for:
Here is the formula:

X position of the cube = X position of the click - (Width of the cube / 2)

And here is my code:
Code:

    public GameObject Cube;
    Collider m_Collider;

private void OnMouseDown()
    {
        m_Collider = GetComponent<Collider>();
        centreHorInPent = (int)(Cube.transform.position.x - (m_Collider.bounds.size.x / 2));
        centreVerInPent = (int)(Cube.transform.position.y - (m_Collider.bounds.size.y / 2));
        Cube.transform.position = new Vector3(centreHorInPent, centreVerInPent, 0);
}

The problem is that the cube does not move to the center of the cursor where the user has clicked.

I found a nice tuto that shows what I’m looking for, but this one is in 2D and the cubes are sprites (see the end of the below tuto).

Thanks for your help

Do you have a question here?
Why are you casting to an int instead of just using a float?

My question is this:

I would like the cube to move to the center of the cursor where the user clicked.
Like in the tutorial above, but with a cube (see the end of the tutorial).

Thanks in advance.