用户工具

站点工具


侧边栏

script:unityengine:classes:transform:transform.parent

Transform.parent 父对象

JavaScript ⇒ var parent: Transform;
C# ⇒ Transform parent;

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.

改变父对象,将修改相对父级的位置、缩放和旋转角度,但是保持和世界坐标的位置、旋转角度和缩放相同。

JavaScript:

	// 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); 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Transform cameraTransform = Camera.main.transform;
    void Example() {
        cameraTransform.parent = transform;
        cameraTransform.localPosition = -Vector3.forward * 5;
        cameraTransform.LookAt(transform);
    }
}

另一个例子:

JavaScript:

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

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Example() {
        transform.parent = null;
    }
}

Transform

script/unityengine/classes/transform/transform.parent.txt · 最后更改: 2016/08/02 05:37 (外部编辑)