Transform.parent Manual     Reference     Scripting  
Scripting > Runtime Classes > Transform
Transform.parent

var parent : Transform

Description

The parent of the transform.

Changing the parent will modify the parent-relative position, scale and rotation but keep the world space position, rotation and scale the same.

// 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 beind the current object
cameraTransform.localPosition = -Vector3.forward * 5;

// make it point towards the object
cameraTransform.LookAt(transform);

// Detaches the transform from its parent.
transform.parent = null;