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.
var cameraTransform =
Camera.main.transform;
cameraTransform.parent = transform;
cameraTransform.localPosition = -Vector3.forward * 5;
cameraTransform.LookAt(transform);
using UnityEngine;
using System.Collections;
public class example :
MonoBehaviour {
public Transform cameraTransform =
Camera.main.transform;
void Awake() {
cameraTransform.parent = transform;
cameraTransform.localPosition = -Vector3.forward * 5;
cameraTransform.LookAt(transform);
}
}
import UnityEngine
import System.Collections
class example(
MonoBehaviour):
public cameraTransform as Transform =
Camera.main.transform
def
Awake():
cameraTransform.parent = transform
cameraTransform.localPosition = ((-Vector3.forward) * 5)
cameraTransform.LookAt(transform)
Another Example
using UnityEngine;
using System.Collections;
public class example :
MonoBehaviour {
void Awake() {
transform.parent = null;
}
}
import UnityEngine
import System.Collections
class example(
MonoBehaviour):
def
Awake():
transform.parent = null