Instantiate cube help.

using UnityEngine;
using System.Collections;

public class construc : MonoBehaviour
{
     public GameObject Builder;

    // placeholder for what you see on the screen.

    private Transform actualBlock;
   

    void Update()
    {

        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 2000))
            {
                Transform actualBlock = hit.transform;
               
                actualBlock.position = hit.point + hit.normal * 1f;
                actualBlock.transform.position = new Vector3(
                Mathf.Round(actualBlock.position.x),
                Mathf.Round(actualBlock.position.y),
                Mathf.Round(actualBlock.position.z)
                );

                GameObject Placement = Instantiate(Builder, actualBlock.transform.position, Quaternion.identity) as GameObject;



            }
            else
            {
                Debug.Log("nothing");
            }
        }
    }
}

I am trying to get this script to Instantiate a cube on to another one from its face, minecraft style.
But what it is doing is also moving the cube that I clicked on. why is it doing that.
I understand I am not making a new transform for actual block but I have no idea how to script how to do it. please help.

You are changing the vector “transform.position” of the cube. That’s why it moves. You should make a separate vector. Then you can give that vector the values you want and use it to instantiate the new cube.

This should work:

if (Input.GetMouseButtonDown (0)) {
	Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	RaycastHit hit;
	
	if (Physics.Raycast (ray, out hit, 2000)) {

		Vector3 position = hit.point + hit.normal * 1f;
				
		position.x = Mathf.Round (position.x);
		position.y = Mathf.Round (position.y);
		position.z = Mathf.Round (position.z);

		GameObject Placement = Instantiate (Builder, position, Quaternion.identity) as GameObject;
		
	} else {
		Debug.Log ("nothing");
	}
}

I believe this is because transforms can’t really be created. So the hit.transform is simply a pointer to the transform of the block you have selected. So when you change the position of the transform it is a pointer to the actual transform of the block thus you are transforming the block.

Instead of having transform, try using a position (remember to new it) and modify that instead of the hit.transform