Instantiating Objects on the Sides of Other Objects

I want to spawn cubes or other prefab models on the sides of a main objects. For instance you would have engines, shields or communication objects. Also being able to rotate objects in the desired orientation. What I know I need to do is to have a script that knows when the mouse is over an object. Then I need it to snap the object to the side of the main object. Then I think this part is much simpler is rotating the object if the right keys are pressed.

When instantiating a prefab, you can set the position right away in the second parameter:

Instantiate(prefab, position, Quaternion.identity);

Second parameter is used to set the position, for examle transform.position.

Third parameter Quaternion.identity is used to set the rotation. However, if you don“t know how Quaternions work, you can store the instatiated object into the variable:

//JavaScript
var clone : GameObject = Instantiate(prefab, position, Quaternion.identity);
clone.transform.eulerAngles = Vector3(x, y, z);

//C#
GameObject clone = (GameObject) Instantiate(prefab, position, Quaternion.identity);
clone.transform.eulerAngles = new Vector3(x, y, z);

You can manipulate with objects created with GameObject.CreatePrimitive the same way:

//JavaScript
var clone : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
clone.transform.position = Vector3(x, y, z);
clone.transform.eulerAngles = Vector3(x, y, z);

//C#
GameObject clone = GameObject.CreatePrimitive(PrimitiveType.Cube);
clone.transform.position = new Vector3(x, y, z);
clone.transform.eulerAngles = new Vector3(x, y, z);