Parenting an instantiated prefab.

Hello, I need help with instantiating a prefab and straight away parenting it to the HeadBone. Here is my current script, if it may help. Thanks in advance if anyone can help! :slight_smile:

var HairNumber : int = 0;
var HairArray : Transform[];
var HairBone : Transform;

function Update(){
if(HairNumber < 0){
HairNumber = 1;
}
if(HairNumber > 1){
HairNumber = 0;
}
}

function OnGUI(){
if(GUI.Button(Rect(10,450,140,140),"")){
Hair();
}
}

function Hair(){
HairNumber +=1;
if(HairNumber == 1){
Instantiate(HairArray[0], HairBone.position, HairBone.rotation);
//This is where I want to parent it to the HeadBone.
}
}

You could do:

function Hair()
{
  HairNumber +=1;
  if(HairNumber == 1){
     var myGo : GameObject; 
     myGo = Instantiate(HairArray[0], HairBone.position, HairBone.rotation) as GameObject;
     myGo.transform.parent = goFather.transform;
  }
}

Just replace the goFather with the father game object.