I need to make an object I Instantiate become the child of another object in my scene when it spawns. I've used google, I can't find anything. Ideas?
Code (csharp): // Makes the camera follow this object by // making it a child of this transform. // Get the transform of the camera var cameraTransform = Camera.main.transform; // make it a child of the current object cameraTransform.parent = transform; // place it behind the current object cameraTransform.localPosition = -Vector3.forward * 5; // make it point towards the object cameraTransform.LookAt(transform); Another example: Code (csharp): // Detaches the transform from its parent. transform.parent = null;
Something like this? Code (csharp): #pragma strict var prefab : Transform; var parentObject : Transform; function Start () { var anObject = Instantiate(prefab, Vector3.zero, Quaternion.identity) as Transform; anObject.parent = parentObject; }