Help attaching an object to another

Hi, so I have been trying to figure this out for a while now and cant seem to come up with how to make it work. What I am trying to do is have it set up so there is a ship model in the world, and when I click on it I will attach a part to it that then becomes a child of the ship model. I am trying to have it set up so you can place parts on the ship wherever you want them, so its kinda like spore but with spaceships. So far I have it where I can place it on the ship but dose not adjust its angle to that of the surface, is there any easy way to do this? Also on another less important note, is there an easy way to restrict placement location to an area, I was thinking of using an empty game object and testing to see if it is inside there, think that could work?

Anyways, here is what I have in code so far:

 var partToAdd:GameObject;

function Update () 
{
	var isPlacing:Number = 0;
	
	if(Input.GetMouseButtonDown(0))
	{
		
		isPlacing=1;
		
	}
	if(Input.GetMouseButtonUp(0))
	{
		isPlacing=0;
		
	}
	if(isPlacing==1)
	{
		placePart();
	}
}
function placePart()
{
	var part:GameObject;
	
	
	//make a space to hold the collision target
	var hit:RaycastHit;
	//fire a ray out from the mousepoint
	var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		part = Instantiate (partToAdd, hit.point, transform.rotation);
		part.transform.parent = this.transform;
	if (Physics.Raycast(ray,hit))
	{
		part.transform.position = hit.point;
	}
}

Everything inside your Update function looks a bit… weird. Couldn’t you just replace everything in it with if(Input.GetMouseButtonDown(0)) { placePart(); } ?

To answer your question, to get the rotation of the surface you want to use the normal of the point you hit. You already have the variable hit : RaycastHit, which contains this normal. So you want to use hit.normal . If the origin of the gameObject you’re instantiating is on the bottom then you simply instantiate it on the hit.point with the rotation of the hit.normal.