Instantiate as child

I'm trying to make it so that when a collision happens, an object is instantiated at an exact point as the child of another object. How can I do this?

I guess you use JS (because most beginners use JS ;) but i prefer C#)

One way would be something like:

var yourPrefab : Transform;
var anotherObject : Transform;

function OnCollisionEnter (collision : Collision){
   var anObject : Transform;
   anObject = Instantiate(yourPrefab,, Quaternion.identity);
   anObject.parent = anotherObject;
   anObject.localRotation = Quaternion.identity; // rotates the object like the parent
   anObject.localPosition = Vector3(XX,YY,ZZ); // define here your "exact point" within the parent

You have to give more information whether you want a exact local or global position and if one of your "objects" is involved in the collision?

You instantiate first, then you parent. You can always set position, and after the parenting, set localPosition if you want, instead.

in c# it had to be done like this. Adding this info for anyone else searching for this solution.

GameObject player;
GameObject playerClone;
	void Start () {
        player = Resources.Load("Player") as GameObject;
        playerClone = GameObject.Find("Player(Clone)");
        playerClone.transform.parent = GameObject.Find("Main Camera").transform;